forked from Ashwin-Dev-P/smartagrothon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (32 loc) · 906 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//To enable .env file
require("dotenv").config({ path: `./.env.${process.env.NODE_ENV}` });
console.log("Environment:", process.env.NODE_ENV);
const express = require("express");
const app = express();
//Cookie
const cookieParser = require("cookie-parser");
app.use(cookieParser());
var cors = require("cors");
const front_end_url = process.env.FRONT_END_URL;
var corsOptions = {
credentials: true,
origin: front_end_url,
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
};
app.use(cors());
//DB connection
require("./src/models/");
//body parser deprecation replacement
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
//import routes
const routes = require("./src/routes/");
app.use(routes);
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});