angularjs - 奇怪... Angular Proxy 无法正常工作

标签 angularjs gruntjs yeoman yeoman-generator-angular

我正在处理 Angular/Laravel 项目,但我在配置 Grunt 代理时遇到了问题正确地,我已经遵循了几个教程并进行了一些研究以解决这个问题,但我没有成功。

问题是配置的 Proxy 没有重定向到主机,我设置将请求从 /localhost:9000/api 转发到 /localhost:8000/api ,但是当我发出请求时:

引荐来源网址:http://localhost:9000/api/whataver
请求网址:http://localhost:9000/api/whatever

正在向同一主机发出请求,因此请求未被正确代理,有什么建议吗?

这是我的 grunt 文件的一部分:

connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: '127.0.0.1',
    livereload: 35729
  },
  proxies: [
      {
          context: '/api',
          host: '127.0.0.1',
          port: 8000,
          https: false,
          changeOrigin: false
      }
  ],
  livereload: {
    options: {
      open: true,
      base: [
       '.tmp',
       '<%= yeoman.app %>'
      ],
      middleware: function (connect,options) {

        var middlewares = [];
        
        if (!Array.isArray(options.base)) {
          options.base = [options.base];
        }

        // Set up the proxy
        middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest);

        //server static files
        middlewares.push(
          modRewrite(['^[^\\.]*$ /index.html [L]']),
          connect.static('.tmp'),
          connect().use(
            '/bower_components',
             connect.static('./bower_components')
          ),
          connect.static(appConfig.app)
        );
        return middlewares;
      }
    }
  }

非常感谢任何帮助,谢谢!

最佳答案

这个答案应该有帮助

AngularJS with Grunt - Connect to another server

严格按照答案中提到的步骤检查您的代码。 你会得到它。

关于angularjs - 奇怪... Angular Proxy 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28593249/

相关文章:

javascript - 练习 angularJS 窗口警报不起作用

gruntjs - 使用一项任务的输出作为另一项任务的输入

gruntjs - grunt-cli 安装问题

gruntjs - 使用 Yeoman/Grunt 项目运行 Apache

node.js - 全栈 Angular 和meanjs之间的区别

angularjs - 如何将 PHP 与 yeoman angular 项目集成

javascript - 来自json数据的AngularJS动态表单(不同类型)

AngularJS - 基于 null 和空数组的隐藏值

javascript - 未找到使用 grunt 运行 jest 的测试

java - 如何分别实现每个字段验证时的错误输出?