【问题标题】:Grunt connect proxy rewrite not works in httpsGrunt 连接代理重写在 https 中不起作用
【发布时间】:2014-09-23 13:41:16
【问题描述】:

我尝试通过这个article 创建一个连接代理。我的代码中几乎所有内容都相同,但我需要通过 https 协议调用一些东西。

connect: {
  options: {
    port: 9000,
      hostname: '0.0.0.0',
      livereload: 35729
  },
  proxies: [{
    context: ['/foo/product', '/foo/somethingelse'],
    host: 'non-https-domain.com',
    changeOrigin: true
    rewrite: {
      '^/foo': ''
    }
  },{
    context: '/productImages',
    host: 'https-domain.com',
    https: true,
    port: 443,  // just trying
    changeOrigin: true,
    rewrite: {
      '^/productImages': ''
    }
  }],
    livereload: {
    // the same like the article
  }
}

/product/somethingelse 运行良好,但 /productImages 不行。

我需要这样称呼它:

localhost:9000/productImages/lot/of/directory/and/finally/a/file.jpg

它应该调用

https://https-domain.com/lot/of/directory/and/finally/a/file.jpg

关键是没有/productImages。但是替换从未发生过。

提前感谢您的帮助!

【问题讨论】:

  • 有错误吗?您使用的是自签名 SSL 证书吗?
  • 没有错误,只是简单的调用了一个错误的url。我不使用自签名证书。
  • 我不是 100% 肯定的,但我相信您在尝试在 localhost 上使用 https 时需要一个自签名证书......它在哪里失败了?
  • 它失败了https-domain.com/productImages/lot/of/directory/and/finally/a/…服务器接到了电话,但是/productImages
  • 你试过不使用 https 吗?

标签: javascript angularjs proxy gruntjs grunt-connect-proxy


【解决方案1】:

我犯了一个愚蠢的错误:名字只有错误!

产品列表有一个/product 代理上下文,图像有一个/productImages。我使用正则表达式来设置这些名称。 "^/product" 也将取代 /productImages。 (我把foo 只用于测试重写)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多