如何解决Gruntfile.js中错误configuration的grunt-connect-proxy设置的404错误?

背景:

我正在尝试将我的grunt服务器实例连接到在localhost上运行在同一台机器上的API服务:8080 / api /。

目前使用grunt-connect-proxy来实现这一点。

问题/问题:

http://localhost:9000/api/user-profile/ Failed to load resource: the server responded with a status of 404 (Not Found) 

我的configuration(下面)是否有一个错误,防止/api请求redirect到localhost:8080的代理服务器?

我的设置(Gruntfile.js):

 var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest; ... // Grunt configuration grunt.initConfig({ // Project settings someApp: appConfig, // The grunt server settings connect: { options: { port: 9000, hostname: 'localhost', livereload: 35729 }, server: { proxies: [ { context: '/api', host: 'localhost', port: 8080, changeOrigin: true } ] }, livereload: { options: { open: true, middleware: function (connect) { return [ proxySnippet, connect.static('.tmp'), connect().use( '/bower_components', connect.static('./bower_components') ), connect.static(appConfig.app), ]; } } }, main: { options: { open: true, base: '<%= homer.main %>' } } } ... grunt.registerTask('live', [ 'clean:server', 'copy:styles', 'configureProxies', 'connect:livereload', 'watch' ]); grunt.registerTask('server', [ 'build', 'connect:main:keepalive' ]); 

在configureProxies任务中指定连接目标(本例中为“服务器”)。

 grunt.registerTask('live', function (target) { grunt.task.run([ 'clean:server', 'copy:styles', 'configureProxies:server', 'connect:livereload', 'watch' ]); }); 
Interesting Posts