forked from vison123/mock-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·42 lines (32 loc) · 1.1 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
var express = require('express');
var bodyParder = require('body-parser');
var Redirect = require('./redirect');
var app = express();
var allowCrossDomain = function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type,Authorization,Accept,X-Requested-With,MX-MainMenuId,MX-ProcessSubMenuId');
next();
}
app.use(bodyParder.json());
app.use(allowCrossDomain);
app.use(express.static('./static'));
function getUrlPath(url) {
return url;
}
app.post(getUrlPath('/api/system/business/login'), function (req, res) {
var mockData = require('./json/login.json');
res.json(mockData);
})
app.post('/*', function (req, res) {
console.log('#########', req.url);
var header = req.headers || {};
Redirect(req.url, req.body, function (chunk) {
res.json(chunk);
}, header);
});
var server = app.listen(3003, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});