-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
50 lines (39 loc) · 1.44 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
// Imports
const express = require("express");
const morgan = require("morgan");
const cors = require("cors");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const courseProcess = require("./routes/course-process");
const loginRouter = require('./routes/login-auth');
const keys = require('./config/keysecrets');
const profileRouter = require('./routes/profile');
const passport = require('passport');
//mongoose.set('debug', true);
const app = express();
//Connect to mongodb
mongoose.connect(`mongodb://${keys.mongoDB.user}:${keys.mongoDB.password}@ds131546.mlab.com:31546/ffcsrusers`, (err) => {
err ? console.log("Error Connecting to the db: " + err) : console.log("Successfully connected to db");
});
// Use BodyParser for handlingPOST Requests
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//Specify Port
const PORT = process.env.PORT || 3005;
// Use Morgan for logging
app.use(morgan("dev"));
// Serve Static Files
app.use(express.static(__dirname + "/client/public"));
// Use cors for Cross origin issues
app.use(cors({exposedHeaders: 'Authorization'}));
app.use(passport.initialize());
// Index Router
app.use("/api",courseProcess);
// Login Router
app.use("/auth",loginRouter);
//Profile Routes
app.use("/profile", profileRouter);
// Listening to PORT
app.listen(PORT, ()=>{
console.log("Listening on PORT: " + PORT);
});