【问题标题】:Having trouble configuring angular and grunt-proxy-connect.在配置 angular 和 grunt-proxy-connect 时遇到问题。
【发布时间】:2014-09-23 05:32:40
【问题描述】:

在配置 angular 和 grunt-proxy-connect 时遇到问题。
我的静态文件已提供服务,但代理的 Web 服务器从未被命中。 这是我正在工作的 gruntfile.js 部分。 实际的 grunt 服务器设置

    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)
        ];
      }

     }
    },

【问题讨论】:

    标签: javascript node.js angularjs proxy gruntjs


    【解决方案1】:

    也许你错过了那部分?

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

    简而言之,在你的 Gruntfile 中找到这个部分(我假设它是由 yeoman angular generator 生成的)

    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 :)
      }],
    

    【讨论】:

    • 为什么是changeOrigin:false
    猜你喜欢
    • 1970-01-01
    • 2014-09-09
    • 2013-11-18
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 2020-04-09
    • 2014-04-21
    • 2021-04-17
    相关资源
    最近更新 更多