-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
56 lines (47 loc) · 1.66 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
47
48
49
50
51
52
53
54
55
56
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
const path = require("path");
const cors = require("cors");
const dotenv = require("dotenv");
dotenv.config();
const appConfig = require("./config/keys.json");
/* initialize the app */
const app = express();
/* middleswares */
//form data middlesware
app.use(bodyParser.urlencoded({ extended: false }));
//json body middlesware
app.use(bodyParser.json());
//cors middlesware
app.use(cors());
//use passport middlesware
app.use(passport.initialize());
//bring the passport strategy
require("./config/passport.js")(passport);
const server_port = process.env.PORT || appConfig.server_port;
const session_secret = process.env.SESSION_SECRET || appConfig.session_secret;
const db_user = process.env.DB_USER || appConfig.db_user;
const db_pass = process.env.DB_PASS || appConfig.db_pass;
const connection_string = process.env.DB_STR || appConfig.connection_string;
mongoose
.connect(connection_string, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => {
console.log("Connected to database!");
})
.catch(err => {
console.log(err.message);
});
const index_route=require('./routes/index');
const admin_route=require('./routes/admin');
const submission_route=require('./routes/submission');
// const problem_route=require('./routes/problems');
app.use('/api/index',index_route);
app.use('/api/admin',admin_route);
app.use('/api/submission',submission_route);
// app.use('/problems',problem_route);
app.listen(server_port,()=>{console.log(`Server started on port ${server_port}!`)});