-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (47 loc) · 1.83 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
57
58
59
const express = require('express');
const bodyParser = require('body-parser');
require('dotenv').config();
const app = express();
var cors = require('cors');
const path = require('path');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
app.use(express.static(path.join(__dirname,"angular-client", "build")));
const fs = require('fs');
const { validateJWT } = require('./utils/jwt');
app.use(express.json());
async function validateToken(req, res, next) {
const token = req.headers.authorization;
if(!token) {
return res.status(400).json({ message: 'Token Not found..' });
}
const result = await validateJWT(token);
next();
}
app.use('/secure', validateToken);
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
//const students = require('./routes/students.routes');
const users = require('./routes/users.routes');
const tests = require('./routes/tests.routes');
const login = require('./routes/login.routes');
const signup = require('./routes/signup.routes');
const forgotPassword = require('./routes/forgotPassword.routes');
const resetPassword = require('./routes/resetPassword.routes');
//app.use('/students', students);
app.use('/secure/users', users);
app.use('/login', login);
app.use('/signup', signup);
app.use('/forgotPassword', forgotPassword);
app.use('/resetPassword', resetPassword);
app.use('/secure/tests', tests);
require('./dbs/mongo_db');
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "angular-client", "build", "index.html"));
});
app.listen(process.env.PORT || 8000, ()=> console.log('Server started on port 3000'));