-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (36 loc) · 1.05 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
const express = require('express');
const app = express();
const { logger } = require('./startup/logging');
const cors = require('cors');
const bodyParser = require('body-parser');
require('dotenv').config();
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
const corsOptions = {
origin: ["*"],
credentials: true,
methods: "POST, PUT, OPTIONS, DELETE, GET",
allowedHeaders: "X-Requested-With, Content-Type, jwtAuthToken"
};
app.use(cors(corsOptions));
app.options('*', cors(corsOptions));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.get('/', async (req, res) => {
res.send({ "msg": "main server is working" })
});
require('./startup/routes.v1')(app);
require('./startup/db')();
require('./startup/config')();
require('./startup/prod')(app);
// port 80 or 5000
const port = process.env.PORT || 5000;
const server = app.listen(port, () => {
console.log(`http://server:${port}`);
console.log('main server is working...');
});
module.exports = server;