Skip to content

Commit 1bcb37b

Browse files
committed
server: add OpenNext response header to track version
1 parent e7c732b commit 1bcb37b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

.changeset/fluffy-trains-fry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"open-next": patch
3+
---
4+
5+
server: add OpenNext response header to track version

packages/open-next/src/adapters/server-adapter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export async function handler(
132132

133133
fixCacheHeaderForHtmlPages(internalEvent.rawPath, headers);
134134
fixSWRCacheHeader(headers);
135+
addOpenNextHeader(headers);
135136
await revalidateIfRequired(
136137
internalEvent.headers.host,
137138
internalEvent.rawPath,
@@ -255,6 +256,10 @@ function fixSWRCacheHeader(headers: Record<string, string | undefined>) {
255256
}
256257
}
257258

259+
function addOpenNextHeader(headers: Record<string, string | undefined>) {
260+
headers["X-OpenNext"] = process.env.OPEN_NEXT_VERSION;
261+
}
262+
258263
async function revalidateIfRequired(
259264
host: string,
260265
rawPath: string,

packages/open-next/src/build.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function normalizeOptions(opts: BuildOptions) {
7171
const appPath = process.cwd();
7272
const outputDir = ".open-next";
7373
return {
74+
openNextVersion: getOpenNextVersion(),
7475
appPath,
7576
appPublicPath: path.join(appPath, "public"),
7677
outputDir,
@@ -167,8 +168,8 @@ function printNextjsVersion() {
167168
}
168169

169170
function printOpenNextVersion() {
170-
const onVersion = require(path.join(__dirname, "../package.json")).version;
171-
console.info(`OpenNext v${onVersion}`);
171+
const { openNextVersion } = options;
172+
console.info(`OpenNext v${openNextVersion}`);
172173
}
173174

174175
function initOutputDir() {
@@ -526,7 +527,7 @@ function addCacheHandler(outputPath: string) {
526527
/********************/
527528

528529
function esbuildSync(esbuildOptions: ESBuildOptions) {
529-
const { appPath, debug } = options;
530+
const { openNextVersion, debug } = options;
530531
const result = buildSync({
531532
target: "esnext",
532533
format: "esm",
@@ -541,6 +542,7 @@ function esbuildSync(esbuildOptions: ESBuildOptions) {
541542
"process.env.OPEN_NEXT_DEBUG": process.env.OPEN_NEXT_DEBUG
542543
? "true"
543544
: "false",
545+
"process.env.OPEN_NEXT_VERSION": `"${openNextVersion}"`,
544546
},
545547
});
546548

@@ -601,3 +603,7 @@ function getBuildId(dotNextPath: string) {
601603
.readFileSync(path.join(dotNextPath, ".next/BUILD_ID"), "utf-8")
602604
.trim();
603605
}
606+
607+
function getOpenNextVersion() {
608+
return require(path.join(__dirname, "../package.json")).version;
609+
}

0 commit comments

Comments
 (0)