-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (39 loc) · 1.24 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
58
// jshint esversion: 6
const express = require('express');
const handleErrors = require('http-errors');
const bodyParser = require('body-parser');
require('dotenv').config();
require('./helpers/mongo.db');
const route = require('./Routes/auth.route');
const userRoute = require('./Routes/user.route');
const courseRoute = require('./Routes/course.route');
const { verifyToken } = require('./helpers/token_helper');
require('events').EventEmitter.defaultMaxListeners = 100;
const app = express();
const PORT = process.env.PORT || 3000;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/auth", route);
app.use("/user/", userRoute);
app.use("/", courseRoute);
app.get("/", verifyToken, function (req, res) {
// const auth_token = req.headers.authorization;
console.log(req.payload);
res.send("message");
});
app.use((req, res, next) => {
var error = handleErrors.NotFound("Page not Found");
next(error);
});
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.send({
error: {
message: error.message,
statusCode: error.status || 500
}
});
});
app.listen(PORT, function () {
console.log("Listening to port 3000");
});