-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
42 lines (35 loc) · 1.05 KB
/
routes.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
37
38
39
40
41
42
const { logger } = require(`${__dirname}/models/logger`)
module.exports = (app) => {
app.use((req, res, next) => {
req.requestTime = Date.now();
next();
});
app.get('/', (req, res) => {
return res.sendFile(`${__dirname}/public/html/fileManager.html`);
});
app.get('/test', (req, res) => {
return res.status(200).json({
'status': 'OK',
'message': `test success`
})
});
app.get('/error', (req, res) => {
return res.status(400).json({
'status': 'ERROR',
'message': 'test error'
})
});
app.use('/file', require(`${__dirname}/api/file`))
app.route('/favicon.ico').get((req, res) => {
return res.send("")
});
// Handle 404 error
app.use((req, res) => {
return res.status(404).sendFile(`${__dirname}/public/html/404.html`);
});
// Handle error
app.use((err, req, res, next) => {
logger.error(new Error(err.stack).stack)
return res.status(500).send('Server error');
});
}