-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
36 lines (34 loc) · 1.1 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const logger = require('morgan');
const compression = require('compression');
const { PRODUCTION, DEVELOPMENT } = require('./utils/environment');
const notFoundMiddleware = require('./middlewares/not-found');
const errorHandlerMiddleware = require('./middlewares/error-handler');
const { BASE_URL } = process.env;
/**
* Import all application routes here
*/
const restaurantRoutes = require('./routes/restaurant');
const userRoutes = require('./routes/user');
const menuRoutes = require('./routes/menu');
const orderRoutes = require('./routes/order');
module.exports = (app) => {
if (process.env.NODE_ENV === DEVELOPMENT) {
app.use(logger('dev'));
}
if (process.env.NODE_ENV === PRODUCTION) {
app.use(compression());
app.set('view cache', true);
}
/**
* Serve application routes as middlewares
*/
app.use(`/${BASE_URL}/restaurants`, restaurantRoutes);
app.use(`/${BASE_URL}/users`, userRoutes);
app.use(`/${BASE_URL}/menu`, menuRoutes);
app.use(`/${BASE_URL}/orders`, orderRoutes);
/**
* Error Middlewares
*/
app.use(errorHandlerMiddleware);
app.use(notFoundMiddleware);
};