-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (35 loc) · 1.24 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
const express = require("express");
const mongoose = require("mongoose");
var app = express();
const port = process.env.PORT || 3000;
const bodyParser = require("body-parser");
const passport = require("passport");
//Middleware for bodyparser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//bring all routes
const auth = require("./routes/api/auth");
const profile = require("./routes/api/profile");
const question = require("./routes/api/question");
const linuxquestion = require("./routes/api/linuxquestion");
//mongoDB configuration
const db = require("./setup/myurl").mongoURL;
//Attempt to connect to db
mongoose
.connect(db, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log("MongoDB Connected successfully"))
.catch(err => console.log(err));
//Passport middlewares
app.use(passport.initialize());
//COnfig for jwt strategy
require("./strategies/jsonwtStrategy")(passport);
//just for testing -> routes
app.get("/", (req, res) => {
res.send("<h1>hello there</h1>");
});
//actual routes
app.use("/api/auth", auth);
app.use("/api/profile", profile);
app.use("/api/question", question);
app.use("/api/linuxquestion", linuxquestion);
app.listen(port, () => console.log("So far so good"));