2014-09-23 96 views
0

无法配置角度和grunt-proxy-connect。
我的静态文件被提供,但代理的Web服务器从未被击中。 这里是gruntfile.js的,我在我工作的部分。 实际咕噜服务器设置无法配置角度和grunt-proxy-connect。

connect: { 
     options: { 
     port: 9000, 
     hostname: 'localhost', 
     livereload: 35729 
     }, 
     proxies: [{ 
     context: '/', // the context of the data service 
     host: 'localhost/', // wherever the data service is running 
     changeOrigin: true, 
     port:3000 
     }], 
     livereload: { 
     options: { 
      open: true, 
      base: [ 
      '.tmp', 
      '<%= yeoman.app %>' 
      ], 
      middleware: function (connect, options) { 
      return [ 
      require('grunt-connect-proxy/lib/utils').proxyRequest, 
      connect.static('.tmp'), 
      connect().use(
      '/bower_components', 
      connect.static('./bower_components') 
     ), 
      connect.static(appConfig.app) 
     ]; 
     } 

    } 
    }, 

回答

1

也许你错过了那一部分?

https://github.com/drewzboto/grunt-connect-proxy#adding-the-configureproxy-task-to-the-server-task

总之,发现在你Gruntfile此部分(I假设它是由约曼角发生器产生)

grunt.task.run([ 
    'clean:server', 
    'wiredep', 
    'concurrent:server', 
    'autoprefixer', 
    'configureProxies:server', // ... and add this line 
    'connect:livereload', 
    'watch' 
]); 

我亦重置代理部为默认值:

proxies: [{ 
    context: '/api', 
    host: 'localhost', // get rid of the '/' 
    changeOrigin: false, 
    port:3000 // hello, fellow Rails developer :) 
    }], 
+0

谢谢你是对的。 – 2014-10-18 11:41:27

+0

为什么'''changeOrigin:false'''? – netalex 2016-12-28 21:21:36