-
Notifications
You must be signed in to change notification settings - Fork 135
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
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/open-next/src/adapters/plugins/14.1/serverHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*eslint-disable simple-import-sort/imports */ | ||
import type { Options, PluginHandler } from "../../types/next-types.js"; | ||
import type { IncomingMessage } from "../../http/request.js"; | ||
import type { ServerlessResponse } from "../../http/response.js"; | ||
//#override imports | ||
//@ts-ignore | ||
import { requestHandler } from "./util.js"; | ||
//@ts-ignore | ||
import { proxyRequest } from "./routing/util.js"; | ||
//#endOverride | ||
|
||
//#override handler | ||
export const handler: PluginHandler = async ( | ||
req: IncomingMessage, | ||
res: ServerlessResponse, | ||
options: Options, | ||
) => { | ||
if (options.isExternalRewrite) { | ||
return proxyRequest(req, res); | ||
} else { | ||
// Next Server | ||
return requestHandler(req, res); | ||
} | ||
}; | ||
//#endOverride |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -692,6 +692,26 @@ async function createServerBundle(monorepoRoot: string, streaming = false) { | |
]; | ||
} | ||
|
||
if (compareSemver(options.nextVersion, "14.1.0") >= 0) { | ||
plugins = [ | ||
openNextPlugin({ | ||
name: "opennext-14.1-serverHandler", | ||
target: /plugins\/serverHandler\.js/g, | ||
replacements: ["./14.1/serverHandler.js"], | ||
}), | ||
openNextPlugin({ | ||
name: "opennext-14.1-util", | ||
target: /plugins\/util\.js/g, | ||
replacements: ["./14.1/util.js", "./util.replacement.js"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only things that change between 13.5.1+ and 14.1 is the 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",
target: /plugins\/serverHandler\.js/g,
replacements: ["./13.5/serverHandler.js"],
}),
openNextPlugin({
name: "opennext-13.5-util",
target: /plugins\/util\.js/g,
replacements: [utilReplacement, "./util.replacement.js"],
}),
openNextPlugin({
name: "opennext-13.5-default",
target: /plugins\/routing\/default\.js/g,
replacements: ["./default.replacement.js"],
}),
];
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM! |
||
}), | ||
openNextPlugin({ | ||
name: "opennext-14.1-default", | ||
target: /plugins\/routing\/default\.js/g, | ||
replacements: ["./default.replacement.js"], | ||
}), | ||
]; | ||
} | ||
|
||
if (streaming) { | ||
const streamingPlugin = openNextPlugin({ | ||
name: "opennext-streaming", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to create this file, just use the
13.5/serverHandler.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that the module resolution could find an error because the file isn't in the same directory so the relative path was supposed to be different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not how the plugin works https://open-next.js.org/inner_workings/plugin
Long story short, the only things that happens is that everything between
//#override
and//#endOverride
is replaced in the files you provide