收到 503 错误:在页面文件夹中添加 getServerSideProps 后,无法满足请求。

huangapple go评论90阅读模式
英文:

Getting 503 ERROR: The request could not be satisfied. after adding getServerSideProps in the pages folder

问题

这是 getServerSideProps 的代码部分,它在你的项目中使用 Next.js 应用程序,托管在 AWS Amplify 上。一切都正常工作,直到我添加了 getServerSideProps 来调用 Lambda 函数获取数据,这是为了 SEO 目的。

以下是 getServerSidePropspages 文件夹中的代码:

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 时,这个特定路由出现了错误消息。

收到 503 错误:在页面文件夹中添加 getServerSideProps 后,无法满足请求。

我已经进行了相关研究,将 Lambda 超时函数设置为 1 分钟,之前是 30 秒(但根据 AWS 文档,应该是 3 秒)。

收到 503 错误:在页面文件夹中添加 getServerSideProps 后,无法满足请求。

此外,我还检查了 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(() =&gt; import(&#39;../../../components/NFTDetails&#39;));
import dynamic from &#39;next/dynamic&#39;;

const CategoryNFT = (data: any) =&gt; {
  return &lt;NftDetails props={data} /&gt;;
};
export default CategoryNFT;

export const getServerSideProps = async (context: any) =&gt; {
  const { nftId } = context.query;
  console.log(&#39;NFT ID ----&gt; &#39;, nftId);
  let requestOptions = {
    method: &#39;GET&#39;,
    headers: {
      &#39;Content-Type&#39;: &#39;application/json&#39;,
    },
  };
  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.

收到 503 错误:在页面文件夹中添加 getServerSideProps 后,无法满足请求。

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 )

收到 503 错误:在页面文件夹中添加 getServerSideProps 后,无法满足请求。

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.

huangapple
  • 本文由 发表于 2023年2月16日 11:53:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75467699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定