私は最終的に私のスキルを超えた問題に遭遇しました。社内の誰もこの問題に精通していません. 私の問題はwindows 7/8
、開発用の現在のnginx構成を置き換えるために、gruntサーバー/サーバーを職場で動作させようとしていることです。
angularjs
フロントエンドとバックエンドの両方をローカルで実行している場合grails
、これを実行しても問題はありませんが、ローカルで grunt serve を介して angularjs アプリを実行し、test.domain.net でデプロイされたバックエンドと通信させたい場合は、プロキシ エラーが発生しています: ECONNRESET error
。
grunt-contrib-connect の 3 つのバージョンを試しまし(0.1.10, 0.1.11, 0.2.0)
た。10 と 11 にはわずかに異なるエラーがありますが、私が好むのは 2 であり、ECONNRESET をスローしているものです。
私にとって非常に奇妙に思えるのは、 --stack --verbose を使用すると、プロキシ経由でリダイレクトしていると主張しているが、クロムでURLを見ると、まだローカルホストを使用していることです。
現在のエラー
> Proxied request: /app/orders?limit=15&offset=0 ->
> https://services-test.app.com:443/orders?limit=15&offset=0
> {
"host": "services-test.app.com", "connection": "keep-alive",
> "cache-control": "max-age=0", "accept": "application/json,
> text/plain, */*", "x-auth-token":
> "3an7h1oupnj6e7shfplf06adn8mr8q26", "if-modified-since": "0",
> "user-agent": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36
> (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/5
> 37.36", "referer": "http://localhost:9000/", "accept-encoding": "gzip, deflate, sdch", "accept-language": "en-US,en;q=0.8",
> "cookie": "_ga=GA1.1.1146585466.1432141723;
> JSESSIONID=5569C3D1BDC2CA2CBF5B72636A9338F4", "x-forwarded-for":
> "127.0.0.1", "x-forwarded-port": "80", "x-forwarded-proto": "http"
> }
> Proxy error: ECONNRESET
Gruntfile.js の関連部分 (URL はプライバシー保護のために変更されています)
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost', //'0.0.0.0',
livereload: 35729
},
proxies: [
{
//context: '/api',
//host: 'localhost',
//port: 8080,
//https: false,
//changeOrigin: false,
//xforward: false
context: '/api',
host: 'services-test.app.com',
https: true,
port: 443,
xforward: true,
headers: {
'host': 'services-test.app.com',
'x-auth-token': '3an7h1oupnj6e7shfplf06adn8mr8q26'
},
rewrite: {
'^/api': ''
}
}
],
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>'
],
middleware: function(connect, options) {
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
// Setup the proxy
var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];
// Serve static files.
options.base.forEach(function(base) {
middlewares.push(connect.static(base));
});
// Make directory browse-able.
var directory = options.directory || options.base[options.base.length - 1];
middlewares.push(connect.directory(directory));
return middlewares;
}
}
},
このstackoverflow here Grunt connect proxy rewrite not works in httpsは私の正確な問題ですが、これは私の問題を解決しません。その他の関連記事 http://www.ngroutes.com/questions/AUuACacna5vEqxqlK1fu/grunt-connect-proxy-proxy-created-but-i-get-a-404.html
この投稿は、gruntfile.js のヘッダーにホストが含まれている理由と、ローカル ホスト以外のエラーで services-test.app.com が表示される理由です。
最後に、これは CORS の問題である可能性があると言っているものを見てきましたが、それは可能かもしれませんが、grunt-contrib-connect のポイントは、私の理解ではサーバー側の変更を行う必要がないことです。
これを解決するのを手伝ってくれる人に感謝します。今日はたくさんのことを調べました。