-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
27 lines (23 loc) · 886 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
var app = (require('express'))(),
apiRouter = require('./app/apiRouter');
(require('node-env-file'))(__dirname + '/.env');
app.use('/api/' + process.env.VERSION, apiRouter);
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods',
'GET, POST, PUT, PATCH, DELETE, OPTIONS');
res.setHeader('Access-Control-Allow-Headers',
'X-Requested-With, content-type, authorization, accept, origin');
res.setHeader('Access-Control-Allow-Credentials', 'true');
if (req.method === "OPTIONS") {
return res.status(200).json({
status: 200,
message: "OPTIONS request"
});
} else {
next();
}
});
app.listen(process.env.PORT, function () {
console.log('Started listening at port ' + process.env.PORT);
});