3 var express = require('express');
4 var cors = require('cors');
5 var env = require('gitter-web-env');
6 var identifyRoute = env.middlewares.identifyRoute;
11 methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
12 maxAge: 600, // 10 minutes
13 allowedHeaders: ['content-type', 'x-access-token', 'authorization', 'accept'],
15 // Rate limiting with dolph
17 'X-RateLimit-Remaining',
22 var router = express.Router({ caseSensitive: true, mergeParams: true });
24 router.get('/', function(req, res) {
25 res.redirect('https://developer.gitter.im');
28 router.use(cors(corsOptions));
29 router.options('*', cors(corsOptions));
31 router.use(require('../web/middlewares/disallow-transfer-encoding-chunked'));
33 router.use('/v1', require('./v1'));
34 router.use('/private', require('./private'));
36 /** These two routes may seem a bit bizare, but we need to mount
37 * /api/private/health_check on the api.gitter.com/api/private/.. even though
38 * everything else is mounted on the root
41 '/api/private/health_check',
42 identifyRoute('api-private-health-check'),
43 require('./private/health-check')
47 '/api/private/health_check/full',
48 identifyRoute('api-private-health-check-full'),
49 require('./private/health-check-full')
52 /* Catch all - return 404 error */
53 if (!process.env.DISABLE_API_404_HANDLER) {
54 router.get('/*', function(req, res, next) {
60 router.use('/', require('../web/middlewares/token-error-handler'));
61 if (!process.env.DISABLE_API_ERROR_HANDLER) {
62 router.use('/', env.middlewares.errorHandler);
65 module.exports = router;