-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
49 lines (40 loc) · 1.3 KB
/
index.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
const config = require(`./config`);
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const gzip = require('compression');
const helmet = require('helmet');
const fileUploader = require('express-fileupload');
const bearerToken = require('express-bearer-token');
const i18n = require('./i18n');
const cors = require('./cors.js');
const log = require('logflake')('app');
const jwt = require('./functions/jwt/');
(async () => {
/** database & crons */
require('./database/');
require('./cronjobs');
/** app && /status **/
const app = express();
const routes = require('./endpoints/routes.js');
await jwt.registerRSA();
cors.guard(app);
app.use(helmet());
app.use(bearerToken());
app.use(i18n.middleware);
app.use(gzip());
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }));
app.use(cookieParser(config.secret));
app.use(fileUploader({ createParentPath: true }));
app.use(config.base, routes);
/** init **/
if (config.stage === 'test') {
module.exports = app;
} else {
app.listen(config.port, () => {
const stage = config.stage || 'development';
log('info', `Server is running with stage "${stage}" on port ${config.port }\nEnv: ${config.envPath}`);
});
}
})();