英文:
Getting 503 ERROR: The request could not be satisfied. after adding getServerSideProps in the pages folder
问题
这是 getServerSideProps
的代码部分,它在你的项目中使用 Next.js 应用程序,托管在 AWS Amplify 上。一切都正常工作,直到我添加了 getServerSideProps
来调用 Lambda 函数获取数据,这是为了 SEO 目的。
以下是 getServerSideProps
在 pages
文件夹中的代码:
const NftDetails = dynamic(() => import('../../../components/NFTDetails'));
import dynamic from 'next/dynamic';
const CategoryNFT = (data: any) => {
return <NftDetails props={data} />;
};
export default CategoryNFT;
export const getServerSideProps = async (context: any) => {
const { nftId } = context.query;
console.log('NFT ID ----> ', nftId);
let requestOptions = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const res = await fetch(
`https://******.amazonaws.com/test/asset/get-asset-by-id?asset_id=${nftId}`,
requestOptions
);
const data = await res.json();
console.log(data);
return {
props: { data },
};
};
在本地环境中一切都正常工作。但当我将代码推送到 Amplify 时,这个特定路由出现了错误消息。
我已经进行了相关研究,将 Lambda 超时函数设置为 1 分钟,之前是 30 秒(但根据 AWS 文档,应该是 3 秒)。
此外,我还检查了 Amplify 项目的日志,显示 30.2 秒后超时
。就是这样。
是否有人知道如何解决这个问题?提前感谢。
英文:
I using the Next.js app for my project, that is hosted in AWS Amplify. All are working fine until I added getServerSideProps
to call the Lambda function to get the data. It is for SEO purpose.
This is the code for getServerSideProps
in pages folder
pages->categories->[categoriesId->[nftId].tsx
const NftDetails = dynamic(() => import('../../../components/NFTDetails'));
import dynamic from 'next/dynamic';
const CategoryNFT = (data: any) => {
return <NftDetails props={data} />;
};
export default CategoryNFT;
export const getServerSideProps = async (context: any) => {
const { nftId } = context.query;
console.log('NFT ID ----> ', nftId);
let requestOptions = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const res = await fetch(
`https://******.amazonaws.com/test/asset/get-asset-by-id?asset_id=${nftId}`,
requestOptions
);
const data = await res.json();
console.log(data);
return {
props: { data },
};
};
In local everything works perfectly fine. But when I pushed the code to amplify. this particular route gives this error message.
I researched about it, I increased the lambda timeout function to 1 minute, previously it was 30 seconds. (but in aws docs it should be 3 seconds )
Also I checked the logs the amplify project, it says timeout after 30.2 seconds
. that's it.
Does anyone knows how to resolve this issue. Thanks in advance.
答案1
得分: 0
在一段时间后,我弄清楚了,在放大设置中,将"web-dynamic"更改为"web-computed"解决了这个问题。
英文:
After a while, I figured this out, In amplify settings, changing web-dynamic to web-computed solved this issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论