-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.js
42 lines (34 loc) · 1.07 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 bodyParser = require('body-parser')
// read .env variable
require('dotenv').config()
// start database connection
let mongoDB = require('./config/mongoHandler')
mongoDB.init()
const router = express.Router();
const app = express()
// install middlewares
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
// authorization middleware
const API_KEY = 'zaCELgL.0imfnc8mVLWwsAawjYr4Rx-Af50DDqtlx'
app.use(function (req, res, next) {
var reqToken = req.get('Authorization');
if (reqToken) {
if (reqToken == 'Bearer '+ API_KEY) {
next();
} else {
res.status(401).json({
"message":"Not Authorized"
})
}
} else {
res.status(401).json({
"message":"Authorization header not found"
})
}
})
// todo item routes
router.use('/item', require('./routes/index'));
app.use('/', router)
app.listen(process.env.PORT, () => console.log(`app running on port ${process.env.PORT}`))