forked from makinhs/rest-api-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (23 loc) · 968 Bytes
/
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
const config = require('./common/config/env.config.js');
const express = require('express');
const app = express();
const AuthorizationRouter = require('./authorization/routes.config');
const UsersRouter = require('./users/routes.config');
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE');
res.header('Access-Control-Expose-Headers', 'Content-Length');
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range');
if (req.method === 'OPTIONS') {
return res.sendStatus(200);
} else {
return next();
}
});
app.use(express.json());
AuthorizationRouter.routesConfig(app);
UsersRouter.routesConfig(app);
app.listen(config.port, function () {
console.log('app listening at port %s', config.port);
});