我终于遇到了一个超出我能力范围的问题,而且内部也没有人非常熟悉手头的问题。我的问题是我试图让 grunt serve/serverwindows 7/8
在工作中工作以替换我们当前的 nginx 配置以进行开发。
如果我angularjs
的前端和grails
后端都在本地运行,我这样做没有问题,但是当我想通过 grunt serve 在本地运行我的 angularjs 应用程序并让它与我们在 test.domain.net 上部署的后端通信时,我收到代理错误:ECONNRESET error
。
我已经尝试了 3 个版本的 grunt-contrib-connect (0.1.10, 0.1.11, 0.2.0)
;10 和 11 的错误略有不同,但 2 是我更喜欢的,并且是抛出 ECONNRESET 的原因。
对我来说似乎特别奇怪的是,使用 --stack --verbose 它声称我正在通过代理进行重定向,但是当我在 chrome 中查看 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;
}
}
},
此处的堆栈溢出 Grunt 连接代理重写在 https中不起作用是我的确切问题,但这并不能解决我的问题。其他相关帖子 http://www.ngroutes.com/questions/AUuACacna5vEqxqlK1fu/grunt-connect-proxy-proxy-created-but-i-get-a-404.html
这篇文章就是为什么我的 gruntfile.js 的标头中包含 host 以及为什么 services-test.app.com 在我的错误中除了本地主机之外都显示。
最后,我看到一些东西说这可能是一个 CORS 问题,虽然这可能是可能的,但 grunt-contrib-connect 的重点是不必在我的理解中进行服务器端更改。
感谢任何可能帮助我解决这个问题的人,对不起,我今天浏览了很多东西,有点漫无目的。