@edgeone/opennextjs-pages 0.2.1 → 0.2.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -250,6 +250,10 @@ var copyPrerenderedContent = async (ctx) => {
|
|
|
250
250
|
...Object.entries(manifest.routes).map(
|
|
251
251
|
([route, meta]) => limitConcurrentPrerenderContentHandling(async () => {
|
|
252
252
|
const key = routeToFilePath(route);
|
|
253
|
+
const isPPR = meta.experimentalPPR === true || meta.renderingMode === "PARTIALLY_STATIC";
|
|
254
|
+
if (isPPR) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
253
257
|
switch (true) {
|
|
254
258
|
// Parallel route default layout has no prerendered page
|
|
255
259
|
case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(
|
|
@@ -59,7 +59,7 @@ const config: NextConfig = {
|
|
|
59
59
|
images: {
|
|
60
60
|
...(originalConfig as any)?.images,
|
|
61
61
|
loader: 'custom',
|
|
62
|
-
loaderFile: './.edgeone/
|
|
62
|
+
loaderFile: './.edgeone/image-loader.mjs',
|
|
63
63
|
},
|
|
64
64
|
};
|
|
65
65
|
|
|
@@ -74,7 +74,7 @@ const config = {
|
|
|
74
74
|
images: {
|
|
75
75
|
...originalConfig?.images,
|
|
76
76
|
loader: 'custom',
|
|
77
|
-
loaderFile: './.edgeone/
|
|
77
|
+
loaderFile: './.edgeone/image-loader.mjs',
|
|
78
78
|
},
|
|
79
79
|
};
|
|
80
80
|
|
|
@@ -89,18 +89,12 @@ module.exports = {
|
|
|
89
89
|
images: {
|
|
90
90
|
...resolved?.images,
|
|
91
91
|
loader: 'custom',
|
|
92
|
-
loaderFile: './.edgeone/
|
|
92
|
+
loaderFile: './.edgeone/image-loader.mjs',
|
|
93
93
|
},
|
|
94
94
|
};
|
|
95
95
|
`;
|
|
96
96
|
}
|
|
97
97
|
function injectImageLoader(cwd) {
|
|
98
|
-
const loaderDir = join(cwd, ".edgeone", "cloud-functions", "ssr-node");
|
|
99
|
-
if (!existsSync(loaderDir)) {
|
|
100
|
-
mkdirSync(loaderDir, { recursive: true });
|
|
101
|
-
}
|
|
102
|
-
const loaderPath = join(loaderDir, "image-loader.mjs");
|
|
103
|
-
writeFileSync(loaderPath, IMAGE_LOADER_CONTENT, "utf-8");
|
|
104
98
|
const config = findNextConfig(cwd);
|
|
105
99
|
if (!config) {
|
|
106
100
|
console.log("[opennext] next.config not found, skipping image loader injection");
|
|
@@ -111,6 +105,17 @@ function injectImageLoader(cwd) {
|
|
|
111
105
|
console.log("[opennext] images.loaderFile already configured, skipping injection");
|
|
112
106
|
return;
|
|
113
107
|
}
|
|
108
|
+
const contentWithoutComments = originalContent.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
109
|
+
if (/unoptimized\s*:\s*true/.test(contentWithoutComments)) {
|
|
110
|
+
console.log("[opennext] images.unoptimized detected, skipping image loader injection");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const edgeoneDir = join(cwd, ".edgeone");
|
|
114
|
+
if (!existsSync(edgeoneDir)) {
|
|
115
|
+
mkdirSync(edgeoneDir, { recursive: true });
|
|
116
|
+
}
|
|
117
|
+
const loaderPath = join(edgeoneDir, "image-loader.mjs");
|
|
118
|
+
writeFileSync(loaderPath, IMAGE_LOADER_CONTENT, "utf-8");
|
|
114
119
|
const configDir = config.path.substring(0, config.path.lastIndexOf("/"));
|
|
115
120
|
const backupPath = join(configDir, `next.config.original${config.ext}`);
|
|
116
121
|
renameSync(config.path, backupPath);
|
|
@@ -125,6 +130,13 @@ function injectImageLoader(cwd) {
|
|
|
125
130
|
console.log("[opennext] Image optimization loader injected");
|
|
126
131
|
}
|
|
127
132
|
function restoreNextConfig(cwd) {
|
|
133
|
+
const loaderPath = join(cwd, ".edgeone", "image-loader.mjs");
|
|
134
|
+
if (existsSync(loaderPath)) {
|
|
135
|
+
try {
|
|
136
|
+
unlinkSync(loaderPath);
|
|
137
|
+
} catch {
|
|
138
|
+
}
|
|
139
|
+
}
|
|
128
140
|
const markerPath = getBackupMarker(cwd);
|
|
129
141
|
if (!existsSync(markerPath)) {
|
|
130
142
|
return;
|
package/dist/build/routes.js
CHANGED
|
@@ -89,6 +89,10 @@ function getDataRoutes(dataRoutes, basePath = "") {
|
|
|
89
89
|
}
|
|
90
90
|
return routes;
|
|
91
91
|
}
|
|
92
|
+
function isPPRRoute(prerenderInfo) {
|
|
93
|
+
if (!prerenderInfo) return false;
|
|
94
|
+
return prerenderInfo.experimentalPPR === true || prerenderInfo.renderingMode === "PARTIALLY_STATIC";
|
|
95
|
+
}
|
|
92
96
|
function getServerRoutes(staticRoutes, prerenderManifest, basePath = "") {
|
|
93
97
|
const routes = [];
|
|
94
98
|
const prerenderRoutes = prerenderManifest?.routes || {};
|
|
@@ -97,7 +101,7 @@ function getServerRoutes(staticRoutes, prerenderManifest, basePath = "") {
|
|
|
97
101
|
continue;
|
|
98
102
|
}
|
|
99
103
|
const prerenderInfo = prerenderRoutes[route.page];
|
|
100
|
-
if (prerenderInfo && prerenderInfo.initialRevalidateSeconds === false) {
|
|
104
|
+
if (prerenderInfo && prerenderInfo.initialRevalidateSeconds === false && !isPPRRoute(prerenderInfo)) {
|
|
101
105
|
continue;
|
|
102
106
|
}
|
|
103
107
|
if (route.namedRegex) {
|
|
@@ -3124,6 +3124,18 @@ var disableFaultyTransferEncodingHandling = (res) => {
|
|
|
3124
3124
|
return originalStoreHeader.call(this, firstLine, headers);
|
|
3125
3125
|
};
|
|
3126
3126
|
};
|
|
3127
|
+
function getRealHostInfo(headers) {
|
|
3128
|
+
const get = (key) => {
|
|
3129
|
+
if (typeof headers.get === "function") {
|
|
3130
|
+
return headers.get(key) || "";
|
|
3131
|
+
}
|
|
3132
|
+
return headers[key] || "";
|
|
3133
|
+
};
|
|
3134
|
+
const host = get("eo-pages-host") || get("host") || "localhost";
|
|
3135
|
+
const protocol = get("x-forwarded-proto") || "https";
|
|
3136
|
+
return { host, protocol };
|
|
3137
|
+
}
|
|
3138
|
+
var NEXT_REQUEST_META = Symbol.for("NextInternalRequestMeta");
|
|
3127
3139
|
var server_default = async (request, _context, topLevelSpan, requestContext) => {
|
|
3128
3140
|
const tracer = getTracer();
|
|
3129
3141
|
if (!nextHandler) {
|
|
@@ -3139,9 +3151,14 @@ var server_default = async (request, _context, topLevelSpan, requestContext) =>
|
|
|
3139
3151
|
});
|
|
3140
3152
|
}
|
|
3141
3153
|
return await tracer.withActiveSpan("generate response", async (span) => {
|
|
3154
|
+
const { host: realHost, protocol: realProtocol } = getRealHostInfo(request.headers);
|
|
3142
3155
|
const headersList = [];
|
|
3143
3156
|
for (var key in request.headers) {
|
|
3144
|
-
|
|
3157
|
+
if (key === "host") {
|
|
3158
|
+
headersList.push([key, realHost]);
|
|
3159
|
+
} else {
|
|
3160
|
+
headersList.push([key, request.headers[key]]);
|
|
3161
|
+
}
|
|
3145
3162
|
}
|
|
3146
3163
|
let bodyStream = request.body;
|
|
3147
3164
|
if (typeof bodyStream === "undefined" && request.method !== "GET" && request.method !== "HEAD") {
|
|
@@ -3166,7 +3183,7 @@ var server_default = async (request, _context, topLevelSpan, requestContext) =>
|
|
|
3166
3183
|
const { req, res } = toReqRes({
|
|
3167
3184
|
...request,
|
|
3168
3185
|
body: bodyStream,
|
|
3169
|
-
url:
|
|
3186
|
+
url: `${realProtocol}://${realHost}${request.url}`,
|
|
3170
3187
|
headers: headersList
|
|
3171
3188
|
});
|
|
3172
3189
|
Object.defineProperty(req, "connection", {
|
|
@@ -3180,6 +3197,21 @@ var server_default = async (request, _context, topLevelSpan, requestContext) =>
|
|
|
3180
3197
|
}
|
|
3181
3198
|
});
|
|
3182
3199
|
disableFaultyTransferEncodingHandling(res);
|
|
3200
|
+
const realOrigin = `${realProtocol}://${realHost}`;
|
|
3201
|
+
const metaProxy = new Proxy({}, {
|
|
3202
|
+
set(target, prop, value) {
|
|
3203
|
+
if (prop === "initURL" && typeof value === "string") {
|
|
3204
|
+
target[prop] = value.replace(/^https?:\/\/localhost(:\d+)?/, realOrigin);
|
|
3205
|
+
} else {
|
|
3206
|
+
target[prop] = value;
|
|
3207
|
+
}
|
|
3208
|
+
return true;
|
|
3209
|
+
},
|
|
3210
|
+
get(target, prop) {
|
|
3211
|
+
return target[prop];
|
|
3212
|
+
}
|
|
3213
|
+
});
|
|
3214
|
+
req[NEXT_REQUEST_META] = metaProxy;
|
|
3183
3215
|
const resProxy = nextResponseProxy(res, requestContext);
|
|
3184
3216
|
const nextHandlerPromise = nextHandler(req, resProxy).catch((error) => {
|
|
3185
3217
|
getLogger().withError(error).error("next handler error");
|
|
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(tags_handler_exports);
|
|
|
28
28
|
|
|
29
29
|
// package.json
|
|
30
30
|
var name = "@edgeone/opennextjs-pages";
|
|
31
|
-
var version = "0.2.
|
|
31
|
+
var version = "0.2.2-beta.2";
|
|
32
32
|
|
|
33
33
|
// src/run/handlers/tags-handler.cts
|
|
34
34
|
var import_request_context = require("./request-context.cjs");
|