-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
58 lines (44 loc) · 1.56 KB
/
app.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
57
// Userful module Imports first
const express = require('express');
const mongoose = require('mongoose');
const bodyparser = require('body-parser');
const passport = require('passport');
// Import all routes
const auth = require('./routes/api/auth');
const profile = require('./routes/api/profile');
const questions = require('./routes/api/questions');
const app = express();
//Middleware for bodyparser
app.use(bodyparser.urlencoded({ extended: false}));
app.use(bodyparser.json()); //Now, We are in APIs world
// DB Config
const db = require('./config/dev').mongodbURI;
// Connect to MongoDB
mongoose
.connect(db, { useNewUrlParser: true }) // Let us remove that nasty deprecation warrning :)
.then(() => console.log('MongoDB Connected...'))
.catch(err => console.log(err));
// passport middleware
app.use(passport.initialize());
//Configuration for passport JWT strategy
require("./strategies/jsonwtStrategy")(passport);
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
});
//------------------------------------
//----- APIs (shiped to route/apis) ---
//For testing purpose only -> route
app.get("/", (req, res) => {
// console.log("Welcome to Qabot");
res.status(200).end("Welcome to QaBot...");
});
// Use routes for access to API endpoints
app.use('/api/auth', auth);
app.use('/api/profile', profile);
app.use('/api/questions', questions);
// Server setup
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Server/App is running on port ${port}`));