-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
38 lines (36 loc) · 1.05 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
const express = require('express');
const cors = require('cors');
const Authentication = require('./middlewares/static');
const FixedAuthentication = require('./middlewares/fixed');
require('dotenv').config()
const app = express();
// middlewares
app.use(cors());
app.use(express.json());
// setting up the PORT
const PORT = process.env.PORT || 8001;
app.get('/static', Authentication.ensureRole('customer'), async (req, res) => {
try {
res.status(200).send({
message: `Congratulations! You made it. Your role is ${req.role}`
})
} catch (error) {
res.status(500).send({
error: 'Internal server error'
})
}
})
app.get('/fixed', FixedAuthentication.Admin, async (req, res) => {
try {
res.status(200).send({
message: `Congratulations! You made it. Your role is ${req.role}`
})
} catch (error) {
res.status(500).send({
error: 'Internal server error'
})
}
})
app.listen(PORT, () => {
console.log(`server is listening at PORT ${PORT}`)
});