2014-09-23 57 views
1

我嘗試通過此article創建連接代理。在我的代碼中,幾乎所有內容都是相同的,但我需要通過https協議調用某些內容。Grunt連接代理重寫不起作用在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。但替換從未發生過。

在此先感謝您的幫助!

+1

是否有錯誤?您是否使用自簽名SSL證書? – mike 2014-09-23 13:49:32

+0

沒有錯誤,只是簡單地調用了一個錯誤的url。我不使用自簽名證書。 – kree 2014-09-23 13:51:37

+0

我不是100%肯定的,但我相信你在嘗試在本地主機上使用https時需要一個自簽名證書......它在哪裏失敗? – mike 2014-09-23 13:55:01

回答

2

我犯了一個愚蠢的錯誤:名稱只有錯誤!

有一個/product產品列表的代理上下文和圖像的/productImages。我使用正則表達式來設置這些名稱。 "^/product"也將取代/productImages。 (我把foo只用於測試重寫)