-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (37 loc) · 1.1 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
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
require('./imports.js')(app);
const jwt = require('./server/JWT/jwt.js');
const PORT = process.env.PORT || 3001;
console.log(process.env.NODE_ENV)
//Set headers
app.use((req, res, next) => {
console.log(req.headers);
res.setHeader('Access-Control-Allow-Headers', 'Content-type,Authorization');
next();
});
app.get('/root', (req,res) => {
console.log("inside the root");
res.status(200).json({
endPoint:'api call to /root',
api: 'Version 1'
})
})
//need to add this to every request -> using the token -> and need to use exjwt to every file
app.get('/api', jwt.getExpressJwt(), (req, res) => {
console.log("Inside /api");
res.status(200).json({
endPoint:'api call to /api',
api: 'Version 1'
})
})
app.get('/homepage', jwt.getExpressJwt(), (req,res) => {
console.log("Web Token Checked.");
res.send('You are authenticated');
})
app.listen(PORT, () => {
console.log(`app is running on port = ${PORT}`)
})