gpt4 book ai didi

next.js - aws 放大 nextjs SSR 不想刷新

转载 作者:行者123 更新时间:2023-12-04 13:52:43 27 4
gpt4 key购买 nike

我正在测试放大 SSR 使用 NextJS。我的本地环境完美运行:我的内容每 60 秒正确刷新一次,但是当我在 AWS AMPLIFY (eu-west-2) 上发布时,内容不想刷新。
这是我使用的来源:https://aws.amazon.com/fr/blogs/mobile/host-a-next-js-ssr-app-with-real-time-data-on-aws-amplify/
下面是一些配置文件:
包.json

{
"name": "poc",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"aws-amplify": "^4.0.3",
"next": "10.2.3",
"react": "17.0.2",
"react-dom": "17.0.2",
"yarn": "^1.22.10"
}
}
索引.js
import { Amplify } from "aws-amplify";
import awsExports from "../aws-exports";
Amplify.configure({ ...awsExports, ssr: true });

export default function Home({date}) {

return (
<>
<b>{date}</b>
</>
);
}

export async function getStaticProps(){
return {
props: {
page,
date:(new Date()).toString()
},
revalidate: 60
}
}
aws-exports.js
const awsmobile = {
"aws_project_region": "eu-west-2"
};


export default awsmobile;
项目-config.json

{
"projectName": "monpoc",
"version": "3.0",
"frontend": "javascript",
"javascript": {
"framework": "react",
"config": {
"SourceDir": ".",
"DistributionDir": "build",
"BuildCommand": "npm run-script build",
"StartCommand": "npm run-script start"
}
},
"providers": [
"awscloudformation"
]
}
Build complete
2021-06-05T17:48:22.315Z [INFO]: Page                              Size     First Load JS
┌ ● / (ISR: 60 Seconds) 1.67 kB 64.7 kB
├ /_app 0 B 63 kB
├ ○ /404 3.06 kB 66.1 kB
└ λ /api/hello 0 B 63 kB
+ First Load JS shared by all 63 kB
├ chunks/framework.c38115.js 42 kB
├ chunks/main.71948a.js 19.4 kB
├ chunks/pages/_app.9e3669.js 571 B
├ chunks/webpack.189c53.js 994 B
└ css/fb7e07ce64500530d3fc.css 194 B
2021-06-05T17:48:22.315Z [INFO]: λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
(ISR) incremental static regeneration (uses revalidate in getStaticProps)
2021-06-05T17:48:23.011Z [INFO]: Done in 14.73s.
2021-06-05T17:48:23.016Z [INFO]: Starting SSR Build...
2021-06-05T17:50:09.606Z [INFO]: SSR Build Complete.
2021-06-05T17:50:10.659Z [INFO]: # Completed phase: build
2021-06-05T17:50:10.660Z [INFO]: ## Build completed successfully
2021-06-05T17:50:10.661Z [INFO]: # Starting caching...
2021-06-05T17:50:10.759Z [INFO]: Creating cache artifact...
2021-06-05T17:50:14.604Z [INFO]: # Cache artifact is: 238MB
2021-06-05T17:50:14.673Z [INFO]: # Uploading cache artifact...
2021-06-05T17:50:17.098Z [INFO]: # Caching completed
2021-06-05T17:50:17.125Z [INFO]: No custom headers found.
2021-06-05T17:50:17.127Z [INFO]: # Starting build artifact upload process...
2021-06-05T17:50:19.102Z [INFO]: # Build artifact is: 18MB
2021-06-05T17:50:19.116Z [INFO]: # Build artifact is: 18MB
2021-06-05T17:50:19.117Z [INFO]: # Uploading build artifact '__artifactsHash.zip'...
2021-06-05T17:50:19.207Z [INFO]: # Uploading build artifact '__artifacts.zip'...
2021-06-05T17:50:19.531Z [INFO]: # Build artifact upload completed
2021-06-05T17:50:19.532Z [INFO]: # Starting environment caching...
2021-06-05T17:50:19.532Z [INFO]: # Environment caching completed
Terminating logging...
我被卡住了:“2021 年 6 月 5 日星期六 17:49:26 GMT+0000(协调世界时)”
SSR 模式似乎有效,但如何正确应用 ISR
预先感谢您的帮助

最佳答案

对于下一个 v11
问题是,如果您使用了环境变量中的重新验证间隔,则 Lamba 函数无法访问该环境变量。我观察到,如果我对重新验证间隔进行硬编码,则页面会使用 ISR 正确刷新。
对于下一个 v9
我在 Next v9 中没有遇到这个问题。

关于next.js - aws 放大 nextjs SSR 不想刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67852760/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com