-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (27 loc) · 796 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
const express = require('express');
const cors = require('cors');
const compression = require('compression');
const cookieParser = require('cookie-parser');
const database = require('./database');
const config = require('./config');
const routes = require('./routes');
const app = express();
// connect to mongoDB
database.init(true); // to run seeds database.init(true);
// express in json format
app.use(express.json());
// add compression
app.use(compression());
// cors
app.use(
cors({
origin: [config.client_urls.app],
credentials: true
})
);
// cookie parser
app.use(cookieParser());
// add a prefix for routes
app.use('/api', routes);
// listen to server at given port
app.listen(config.port, () => console.info('server listening at port:', config.port));