javascript - 504 (Gateway Time-out) issue - Stack Overflow

I have a nodeexpress api deployed (api.mysite)In the express app, I have used app.use(cors());In the f

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
 |  Show 6 more ments

1 Answer 1

Reset to default 3

Set 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;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744962226a4603458.html

相关推荐

  • javascript - 504 (Gateway Time-out) issue - Stack Overflow

    I have a nodeexpress api deployed (api.mysite)In the express app, I have used app.use(cors());In the f

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信