我正在使用"^0.2.0"的grunt-connect-proxy来代理我的angularjs应用程序中的api。这个项目是用yeoman angular-generator开始的。
我按照这里的说明进行操作,但在使用代理时出现以下错误:
我按照这里的说明进行操作,但在使用代理时出现以下错误:
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'
]);
});
编辑 目前通过Postman访问localhost:8080/users会返回403,因此API正在运行。