Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cache Support for [email protected] #356

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/open-next/src/adapters/plugins/14.1/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { NextConfig } from "../../config";
import { debug } from "../../logger.js";

//#override requestHandler
// @ts-ignore
export const requestHandler = new NextServer.default({
conf: {
...NextConfig,
// Next.js compression should be disabled because of a bug in the bundled
// `compression` package — https://github.com/vercel/next.js/issues/11669
compress: false,
// By default, Next.js uses local disk to store ISR cache. We will use
// our own cache handler to store the cache on S3.
cacheHandler: `${process.env.LAMBDA_TASK_ROOT}/cache.cjs`,
Manuel-Antunes marked this conversation as resolved.
Show resolved Hide resolved
cacheMaxMemorySize: 0,
experimental: {
...NextConfig.experimental,
// This uses the request.headers.host as the URL
// https://github.com/vercel/next.js/blob/canary/packages/next/src/server/next-server.ts#L1749-L1754
trustHostHeader: true,
},
},
customServer: false,
dev: false,
dir: __dirname,
}).getRequestHandler();
//#endOverride

//#override requireHooks
debug("No need to override require hooks with next 13.4.20+");
//#endOverride
6 changes: 5 additions & 1 deletion packages/open-next/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
: undefined;

if (compareSemver(options.nextVersion, "13.5.1") >= 0) {
const utilReplacement =
compareSemver(options.nextVersion, "14.1.0") >= 0
? "./14.1.util.js"
: "./13.5/util.js";
plugins = [
openNextPlugin({
name: "opennext-13.5-serverHandler",
Expand All @@ -682,7 +686,7 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
openNextPlugin({
name: "opennext-13.5-util",
target: /plugins\/util\.js/g,
replacements: ["./13.5/util.js", "./util.replacement.js"],
replacements: [utilReplacement, "./util.replacement.js"],
}),
openNextPlugin({
name: "opennext-13.5-default",
Expand Down