-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (35 loc) · 1.01 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
import express from 'express';
import bodyParser from 'body-parser';
import {MongoHelper} from 'pkmongo';
import user from './routes/user';
let app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
});
MongoHelper.initialize('mongodb://localhost:27017/test');
app.get('/',(req,res,next)=>{
res.data = {
'text':'Hello PK!'
};
next();
})
app.use('/user',user);
app.use( (req, res, next) => {
if (!res.data) {
res.status(404).send({
status:false,
response:'404 Not Found!'
});
return;
}
res.status(200).send({
status: true,
response: res.data
});
});
module.exports = app;