-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
67 lines (55 loc) · 1.53 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// http://localhost:7001/users/api/mock/2
const express = require('express');
var cors = require('cors')
const http = require('http');
const bodyParser = require("body-parser");
// node simple
// const app = http.createServer(function(req, res){
// });
const app = express();
//app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json({extended: false}));
//app.use(express.urlencoded({extended: false}));
const allowedOrigins = ['localhost', '15.207.254.188'];
app.use(cors({
origin: function(origin, callback){
if (!origin) {
return callback(null, true);
}
if (allowedOrigins.includes(origin)) {
const msg = 'The CORS policy for this site does not allow access from the specified Origin.';
return callback(new Error(msg), false);
}
return callback(null, true);
}
}));
app.use((req, res, next)=>{
console.log("first");
res.locals.city="noida";
next();
});
app.use((req, res, next)=>{
console.log(res.locals.city, "city")
next();
});
app.use('/avinash',(req, res, next)=>{
// console.log(req.body);
res.send("<h1>this is avinash page</h1>");
// res.redirect('/')
})
const adminRoutes = require('./routes/admin');
app.use('/users', adminRoutes);
app.use('/kav',(req, res, next)=>{
// console.log(req.body);
res.send("this is kav page");
// res.redirect('/')
})
app.use('/index',(req, res, next)=>{
res.send("this is home page");
})
app.use((req, res)=>{
res.status(404).send("<h1>page not found</h1>");
})
app.listen(7001, ()=>{
//console.log("listen port")
})