我在gulp-connect
和之间进行通信时遇到问题gulp-stubby-server
。
gulp-connect
正在端口 3006 上运行,而 stubby 正在端口 8000 上运行,但不知何故,它试图仅连接到端口 3006 上的 stubby,我收到 404 错误。我已经完成了代理中间件配置以将所有路径请求重定向/my-server
到 stubby 服务器,但它似乎不起作用。我在这里想念什么?
angular.js:12185 POST http://localhost:3006/my-server/services/getTestData 404(未找到)
var configuration = {
myProxy: _.extend(url.parse('http://localhost:8000/my-server/'), {route: '/my-server'})
}
gulp.task('static', function () {
connect.server({
root: ['target'],
port: 3006,
livereload: false,
middleware: function () {
return [
proxy(configuration.myProxy)
];
}
});
});
gulp.task('stubby', function (cb) {
var options = {
files: [
'mocks/test/*.{json,yaml,js}'
],
callback: function (server, options) {
server.get(1, function (err, endpoint) {
if (!err) {
console.log(endpoint);
}
});
},
stubs: 8000,
tls: 8443,
admin: 8010
};
stubby(options, cb);
});
示例 mock.json
{
"request" : {
"url": "^/my-server/services/getTestData$",
"method": "GET"
},
"response":{
"status" : 200,
"headers" :{
"Content-Type" : "application/json"
},
"latency" : 1000,
"body" : "Some Test Data"
}
}
资源
var testResource = function($resource , CONS){
console.log('test resource');
var requestURL = '/my-server/services/getTestData';
return $resource(requestURL , {},{
getTestData: {
method: 'POST'
}
});
};