admin管理员组文章数量:1406039
I have a node/express api deployed (api.mysite)
In the express app, I have used app.use(cors());
In the frontend I have a nuxt/vue site (www.mysite).
The vue site uses the api to fetch some data. The problem is that most times it works fine. But some times (2 out of 10), I get the following error:
Failed to load resource: the server responded with a status of 504 (Gateway Time-out)
Access to XMLHttpRequest at 'api.mysite' from origin 'www.mysite' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I've read a lot but cannot figure out why it's happening specially why only sometimes and not the other times?
I have a node/express api deployed (api.mysite.)
In the express app, I have used app.use(cors());
In the frontend I have a nuxt/vue site (www.mysite.).
The vue site uses the api to fetch some data. The problem is that most times it works fine. But some times (2 out of 10), I get the following error:
Failed to load resource: the server responded with a status of 504 (Gateway Time-out)
Access to XMLHttpRequest at 'api.mysite.' from origin 'www.mysite.' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I've read a lot but cannot figure out why it's happening specially why only sometimes and not the other times?
Share Improve this question edited Jan 10, 2020 at 5:25 sideshowbarker♦ 88.6k30 gold badges215 silver badges212 bronze badges asked Feb 18, 2019 at 3:42 asanasasanas 4,28015 gold badges52 silver badges82 bronze badges 11- What did you use to fetch date in the front-end side? – Vu Luu Commented Feb 18, 2019 at 3:51
- @vuluu In the front-end, I use axios to call the api. – asanas Commented Feb 18, 2019 at 4:00
- And it's a post request – asanas Commented Feb 18, 2019 at 4:03
- 1 I think the cors error is a red herring. It looks like your api is (sometimes) taking too long to respond which could be for lots of reasons. Try either making axios have no timeout, or try debugging requests to your api. – Countingstuff Commented Mar 17, 2019 at 15:44
- Where are you hosting the server?. You're behind a load balancer and it's ending the request due to the server not responding. – Marcos Casagrande Commented Mar 17, 2019 at 21:49
1 Answer
Reset to default 3Set the timeout to a higher value. If your request is taking more time to be served than the current timeout it throws Gateway Timeout
var server= http.createServer(app).listen(port, function()
{
console.log("Listening on port " + port)
})
server.timeout = 240000;
本文标签: javascript504 (Gateway Timeout) issueStack Overflow
版权声明:本文标题:javascript - 504 (Gateway Time-out) issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744962226a2634726.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论