使用gulp将ajax请求转为本地JSON数据:
var gulp = require('gulp');
gulp.task('webserver', function() {
gulp.src('./app').pipe(webserver({
livereload: true,
directoryListing: {
enable: true,
path: 'app'
},
host: '127.0.0.1',
port: 8000,
middleware: function(req, res, next) {
var urlObj = url.parse(req.url, true),
method = req.method;
switch (urlObj.pathname) {
case '/api/orders':
var data = {
"status": 0,
"errmsg": "",
"data": [{}]
};
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(data));
return;
case '/api/goods':
// ...
return;
case '/api/images':
// ...
return;
default:
;
}
next();
}
}));
});