[英]next.js api route, 504 timeout in aws EC2 when calling some external api url
I have a following Next.js api
route for testing purpose.我有以下
Next.js api
路线用于测试目的。
All 4 axois call work perfectly in localhost;所有 4 个 axois 调用都可以在 localhost 中完美运行; But when in production (hosted by AWS EC2);
但是在生产中(由 AWS EC2 托管); The last 2 calls failed with a reason of
504 gateway time-out
.最后 2 次调用失败,原因是
504 gateway time-out
。
I had thought of nginx
and AWS in-bound/out-bound
setup, but if that's the case, the first two mock api shouldn't work as well.我曾想过
nginx
和 AWS in-bound/out-bound
设置,但如果是这种情况,前两个模拟 api 应该也不能正常工作。
I don't know why it happens.我不知道为什么会这样。 Or it has something to do with api protection from those website?
或者它与那些网站的 api 保护有关? But then why it work in localhost
但是为什么它在本地主机中工作
import axios from "axios";
import { NextApiHandler } from "next";
export default const MockApi: NextApiHandler = async (req, res) => {
try {
// mock set
// work in localhost and production
const { data: testData } = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
console.log(testData);
const { data: mockData } = await axios.get("https://reqres.in/api/users?page=2");
console.log(mockData);
// some real life api
// work in localhost but failed in production with 504 gateway time-out
const { data: mockData2 } = await axios.get("https://www.target.com.au/ws-api/v1/target/products/search?category=W95362");
console.log(mockData2);
const { data } = await axios.get("https://api.nasdaq.com/api/ipo/calendar");
console.log(data);
res.status(200).send({});
} catch (err) {
res.status(403).json(err);
}
};
After investigation, it seems like the problem has something to do with AWS internal policies, so that you are not able to use AWS services to abuse particular affiliated companies and some public APIs.经调查,问题似乎与 AWS 内部政策有关,因此您无法使用 AWS 服务滥用特定关联公司和一些公共 API。
This answer could be incorrect if someone is able to sort the issue out.如果有人能够解决问题,这个答案可能是不正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.