我在gulp-connect
和gulp-stubby-server
之间进行沟通时遇到了问题。
gulp-connect
正在端口3006上运行,而stubby正在端口8000上运行,但不知怎的,它只是尝试连接到端口3006上的stubby而我收到404错误。我已经完成了代理中间件配置,将路径/my-server
的所有请求重定向到短粗服务器,但似乎无法正常工作。我在这里缺少什么?
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'
}
});
};
答案 0 :(得分:1)
查看您发布的错误日志:
angular.js:12185 POST http://localhost:3006/my-server/services/getTestData 404(未找到)
这是services.Configure<CookieAuthenticationOptions>(options =>
{
options.LoginPath = new PathString("/Account/Login");
});
请求,但您只是在 mock.json 文件中模拟了[Authorize]
public class HomeController : Controller
{
...
}
个请求。您需要同时允许POST
和GET
个请求:
POST