This repository was archived by the owner on Sep 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (36 loc) · 1.29 KB
/
index.js
File metadata and controls
45 lines (36 loc) · 1.29 KB
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
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const path = require('path');
const passport = require('passport');
const JwtStrategy = require('./passport');
const mainRouter = require('./routes/mainRouter');
const selectEnvironment = require('./helpers/selectEnvironment');
const errorHandler = require('./middleware/errorHandler');
const DataMaster = require('./controllers/DataMaster');
// select between dev and prod environments based off process.argv[2]
selectEnvironment(process.argv[2]);
const app = express();
// process.env -> change it accordingly!
const connector = new DataMaster();
connector.connectForMutations(process.env.DB_NAME);
/* Added on 3/5/2019
* 1. body parser middleware
* 2. form data
* 3. CORS middleware
*/
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cors());
// static middleware
app.use(express.static(path.join(__dirname, 'public')));
// authentication middleware
app.use(passport.initialize());
passport.use(JwtStrategy);
// Route endpoints -> just the main router
// then main router distributes to the subrouters
app.use('/', mainRouter);
// Error Handling
app.use(errorHandler);
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`listening on port ${PORT}`));