我正在使用ECS/Fargate在AWS上部署一个Next.js应用程序(由于需要自定义日志记录和监视,无法使用扩容)。我的应用程序是使用api路由和动态路由的服务器端呈现(GetServerSideProps).
让我们说,对于SSRed页面,URL类似于:domain.com/foopage/[id]?powerlevel=10000。
“守则”的内容如下:
// pages/foopage/[id].tsx
import React from "react";
import type { GetServerSideProps } from "next";
import Head from "next/head";
export default function FooPage({ id }: Record<string, string>) {
return (
<div>
<Head>
<title>Title</title>
</Head>
<main>
<h1>
Say Hi to <a href="https://sample-url.com/id">{id}</a>!
</h1>
</main>
</div>
);
}
export const getServerSideProps: GetServerSideProps = async (context) => {
context.res.setHeader(
"Cache-Control",
"public, s-maxage=10, stale-while-revalidate=59"
);
const { id } = context.query;
const response = await fetch(
`${process.env.CMS_URL}/api/configurations?id=${id}`
);
const jsonResponse = await response.json();
return {
props: { id },
};
};我希望缓存这些页面,这样服务器就不必每次都生成页面。
我知道,如果您正在使用Vercel,边缘缓存不需要配置即可工作。但由于业务需求,我一定要使用AWS。那么在AWS中该怎么做呢?是否可以使用Lambda@Edge,如果可以,那么可以使用lambda函数吗?
发布于 2022-08-23 12:16:24
我知道,如果您正在使用Vercel,边缘缓存不需要配置即可工作。但由于业务需求,我一定要使用AWS。那么在AWS中该怎么做呢?
如果需要边缘缓存,则需要使用CDN。亚马逊的CDN是CloudFront。
https://stackoverflow.com/questions/73453185
复制相似问题