Grunt connect proxy rewrite not works in https

2019-08-03 20:40发布

问题:

I try to create a connect proxy by this article. Almost everything is the same in my code, but I need to call something across https protocol.

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
  }
}

The /product and the /somethingelse works well, but the /productImages not.

I need to call it like this:

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

and it should call the

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

the point is that without /productImages. But the replace never happened.

Thanks in advance for the help!

回答1:

I made a stupid mistake: There is only error with the names!

There is a /product proxy context for the product list, and a /productImages for the images. I use regex to set these names. And the "^/product" will replace the /productImages too. (I put the foo only for testing the rewrite)