-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (34 loc) · 983 Bytes
/
server.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
const express = require('express');
const dotenv = require('dotenv');
const colors = require('colors');
const morgan = require('morgan');
// init express
const app = express();
// deployment: fix CORS
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept',
);
res.header(
'Access-Control-Allow-Methods',
'GET, POST, OPTIONS, PUT, PATCH, DELETE',
);
next();
});
// init env
dotenv.config({ path: './config/config.env' });
// init route
const bigDays = require('./routes/bigDays');
// init db
const connectDB = require('./config/db');
connectDB();
// enable BodyParser to allow add new data as json
app.use(express.json());
// setup PORT
const PORT = process.env.PORT || 5000;
// GET from server
app.use('/api/v1/bigDays', bigDays);
// server listening
app.listen(PORT, console.log(`Server OK: ${process.env.PORT}`.yellow.bold));