forked from voicelive/VLive_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (26 loc) · 843 Bytes
/
app.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
const express = require('express');
const initialLoaders = require('./loader');
const index = require('./routes');
const episode = require('./routes/episode');
const channel = require('./routes/channel');
const chat = require('./routes/chat');
const { NotFoundError } = require('./lib/errors');
const { ROUTES } = require('./constants/routes');
const app = express();
initialLoaders(app);
app.use(ROUTES.INDEX, index);
app.use(ROUTES.EPISODE, episode);
app.use(ROUTES.CHANNEL, channel);
app.use(ROUTES.CHAT, chat);
app.use((req, res, next) => {
next(new NotFoundError());
});
app.use((err, req, res, _) => {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500).json({
result: 'error',
message: err.message,
});
});
module.exports = app;