我使用grunt-connect-proxy「^ 0.2.0」代理我的angularjs應用程序的api。該項目從yeoman角發電機開始。Grunt連接代理:404沒有找到
我跟着指示here,但使用的代理時,我得到:
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:9000/api/users
我的代理配置:
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
proxies: [{
context: '/api', // the context of the data service
host: 'localhost', // wherever the data service is running
port: 8080, // the port that the data service is running on
https: false,
xforward: false
}],
我中間件:
livereload: {
options: {
open: true,
base: '',
middleware: function (connect, options) {
var middlewares = [];
middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest);
middlewares.push(connect.static('.tmp'));
middlewares.push(connect.static('test'));
middlewares.push(connect().use(
'/bower_components',
connect.static('./bower_components')
));
middlewares.push(connect.static(appConfig.app));
return middlewares;
}
}
},
我的發球任務
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'wiredep',
'concurrent:server',
'autoprefixer:server',
'configureProxies:server',
'connect:livereload',
'watch'
]);
});
編輯 本地主機:8080 /用戶返回當前通過郵遞員403,因此API運行。
您是否嘗試使用服務器:{}之前的選項? –
看看這個問題..也許它會幫助https://stackoverflow.com/questions/34321143/adding-grunt-connect-proxy-to-generator-angular-gruntfile-js – aprok