-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (32 loc) · 1.56 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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var cors = require('cors');
var user = require("./user/UserController");
// ───────────────────────────────────────────────────────────── CROSS ORIGIN ─────
app.use(cors());
//
// ──────────────────────────────────────────────────────────── PARSE REQUEST DATA ─────
app.use(bodyParser.json());
// ──────────────────────────────────────────────────── VALIDATION AUTH TOKEN ─────
app.use('/', function (req, res, next) {
let token = req.headers['x-access-token'] || req.headers['authorization'];
if (token === 'Bearer 1Br4RPWEqvSB9pkox1Q6') {
// token successfully matched
next();
return;
}
// if token is invalid
res.status(401).send("Invalid token.")
});
app.use("/user", user);
//
// ───────────────────────────────────────────────────────────────── LISTENER ─────
app.listen("4222", function (err, rows) {
if (err) {
res.json(err);
} else {
console.log("Server Started..");
}
});
module.exports = app;