-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
52 lines (43 loc) · 1.25 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const express = require('express');
const debug = require('debug');
const morgan = require('morgan');
const helmet = require('helmet');
const cors = require('cors');
const compression = require('compression');
const rfs = require('rotating-file-stream');
const path = require('path');
require('dotenv').config();
const app = express();
const accessLogStream = rfs.createStream('access.log', {
size: '10M', // rotate every 10 MegaBytes written
interval: '1d', // rotate daily
path: path.join(__dirname, 'log'),
});
let loggerOptions = {
stream: accessLogStream,
};
if (process.env.NODE_ENV === 'development') {
loggerOptions = {};
}
const logger = morgan('combined', loggerOptions);
app.use(logger);
app.use(cors());
// app.use(helmet({
// contentSecurityPolicy: false,
// }));
app.use(helmet());
app.use(compression());
app.use(express.json({ limit: '80mb' }));
app.set('view engine', 'ejs');
const seInterfaceRouter = require('./routes/s3interface');
app.use('/files', seInterfaceRouter);
app.use('/', require('./routes'));
app.get('/', (req, res) => {
res.json({ msg: 'Zhir.io API' });
});
// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
debug.error(err.stack);
res.status(500).send(err.toString());
});
module.exports = app;