加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Grunt Connect代理:404未找到

发布时间:2020-12-17 07:27:01 所属栏目:安全 来源:网络整理
导读:我正在使用 grunt-connect-proxy“^ 0.2.0”从我的angularjs应用程序代理api.该项目由yeoman角度发电机启动. 我按照说明here但是当使用代理时,我得到: Failed to load resource: the server responded with a status of 404 (Not Found)http://localhost:90
我正在使用 grunt-connect-proxy“^ 0.2.0”从我的angularjs应用程序代理api.该项目由yeoman角度发电机启动.

我按照说明here但是当使用代理时,我得到:

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

编辑
localhost:8080 / users目前通过Postman返回403,因此API正在运行.

没有直接回答你的问题,而是提供解决方案(因为没有其他人回答)…你有没有试过npm模块connect-modrewrite

这正是你想要做的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读