@edgeone/nuxt-pages 1.0.0
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.
- package/README.md +275 -0
- package/dist/build/content/server.js +18 -0
- package/dist/build/content/static.js +17 -0
- package/dist/build/functions/server.js +19 -0
- package/dist/build/plugin-context.js +18 -0
- package/dist/build/routes.js +18 -0
- package/dist/build/templates/nuxt-handler-backup.js +305 -0
- package/dist/build/templates/nuxt-handler-monorepo.tmpl-ipx_backup.js +511 -0
- package/dist/build/templates/nuxt-handler-monorepo.tmpl.js +243 -0
- package/dist/build/templates/nuxt-handler.tmpl.js +212 -0
- package/dist/esm-chunks/chunk-5YBUNNZ4.js +81 -0
- package/dist/esm-chunks/chunk-6BT4RYQJ.js +43 -0
- package/dist/esm-chunks/chunk-6YERJDAJ.js +208 -0
- package/dist/esm-chunks/chunk-GX4Z7KQX.js +15065 -0
- package/dist/esm-chunks/chunk-HBXUWFGE.js +19 -0
- package/dist/esm-chunks/chunk-HY3HNABZ.js +87 -0
- package/dist/esm-chunks/chunk-KGYBHZC3.js +1467 -0
- package/dist/esm-chunks/chunk-MMMRMLH2.js +132 -0
- package/dist/esm-chunks/chunk-NJ4SUJNF.js +5635 -0
- package/dist/esm-chunks/chunk-QG7JLDXY.js +127 -0
- package/dist/esm-chunks/chunk-RPSYO4VM.js +562 -0
- package/dist/esm-chunks/chunk-UOPC2N5A.js +69 -0
- package/dist/esm-chunks/chunk-V2LFVP3C.js +838 -0
- package/dist/index.js +61 -0
- package/dist/run/config.js +17 -0
- package/dist/run/constants.js +17 -0
- package/dist/run/handlers/cache.cjs +1410 -0
- package/dist/run/handlers/nuxt-cache.cjs +200 -0
- package/dist/run/handlers/nuxt-server.js +156 -0
- package/dist/run/handlers/request-context.cjs +148 -0
- package/dist/run/handlers/server.js +77 -0
- package/dist/run/handlers/tags-handler.cjs +177 -0
- package/dist/run/handlers/tracer.cjs +1004 -0
- package/dist/run/handlers/use-cache-handler.js +220 -0
- package/dist/run/handlers/wait-until.cjs +123 -0
- package/dist/run/headers.js +17 -0
- package/dist/run/revalidate.js +34 -0
- package/dist/run/storage/regional-blob-store.cjs +64 -0
- package/dist/run/storage/request-scoped-in-memory-cache.cjs +1582 -0
- package/dist/run/storage/storage.cjs +191 -0
- package/dist/shared/blob-types.cjs +37 -0
- package/dist/shared/blobkey.js +25 -0
- package/dist/shared/cache-types.cjs +33 -0
- package/dist/shared/nuxt-cache-types.cjs +18 -0
- package/dist/types/options.js +6 -0
- package/dist/utils.js +25 -0
- package/package.json +58 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/run/handlers/nuxt-cache.cts
|
|
21
|
+
var nuxt_cache_exports = {};
|
|
22
|
+
__export(nuxt_cache_exports, {
|
|
23
|
+
EdgeOneNuxtCacheHandler: () => EdgeOneNuxtCacheHandler,
|
|
24
|
+
createEdgeOneNuxtCacheHandler: () => createEdgeOneNuxtCacheHandler
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(nuxt_cache_exports);
|
|
27
|
+
|
|
28
|
+
// src/run/handlers/request-context.cts
|
|
29
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
30
|
+
|
|
31
|
+
// node_modules/@netlify/functions/dist/internal.js
|
|
32
|
+
var import_process = require("process");
|
|
33
|
+
var systemLogTag = "__nfSystemLog";
|
|
34
|
+
var serializeError = (error) => {
|
|
35
|
+
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
36
|
+
return {
|
|
37
|
+
error: error.message,
|
|
38
|
+
error_cause: cause,
|
|
39
|
+
error_stack: error.stack
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
var SystemLogger = class _SystemLogger {
|
|
43
|
+
fields;
|
|
44
|
+
logLevel;
|
|
45
|
+
constructor(fields = {}, logLevel = 2) {
|
|
46
|
+
this.fields = fields;
|
|
47
|
+
this.logLevel = logLevel;
|
|
48
|
+
}
|
|
49
|
+
doLog(logger, message) {
|
|
50
|
+
if (import_process.env.NETLIFY_DEV && !import_process.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
54
|
+
}
|
|
55
|
+
log(message) {
|
|
56
|
+
if (this.logLevel > 2) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.doLog(console.log, message);
|
|
60
|
+
}
|
|
61
|
+
debug(message) {
|
|
62
|
+
if (this.logLevel > 1) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.doLog(console.debug, message);
|
|
66
|
+
}
|
|
67
|
+
error(message) {
|
|
68
|
+
if (this.logLevel > 3) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.doLog(console.error, message);
|
|
72
|
+
}
|
|
73
|
+
withLogLevel(level) {
|
|
74
|
+
return new _SystemLogger(this.fields, level);
|
|
75
|
+
}
|
|
76
|
+
withFields(fields) {
|
|
77
|
+
return new _SystemLogger(
|
|
78
|
+
{
|
|
79
|
+
...this.fields,
|
|
80
|
+
...fields
|
|
81
|
+
},
|
|
82
|
+
this.logLevel
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
withError(error) {
|
|
86
|
+
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
87
|
+
return this.withFields(fields);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var systemLogger = new SystemLogger();
|
|
91
|
+
|
|
92
|
+
// src/run/handlers/request-context.cts
|
|
93
|
+
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
94
|
+
var REQUEST_COUNTER_KEY = Symbol.for("nf-request-counter");
|
|
95
|
+
var extendedGlobalThis = globalThis;
|
|
96
|
+
var requestContextAsyncLocalStorage;
|
|
97
|
+
function getRequestContextAsyncLocalStorage() {
|
|
98
|
+
if (requestContextAsyncLocalStorage) {
|
|
99
|
+
return requestContextAsyncLocalStorage;
|
|
100
|
+
}
|
|
101
|
+
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
102
|
+
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
103
|
+
}
|
|
104
|
+
const storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
105
|
+
requestContextAsyncLocalStorage = storage;
|
|
106
|
+
extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
|
|
107
|
+
return storage;
|
|
108
|
+
}
|
|
109
|
+
var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
110
|
+
function getLogger() {
|
|
111
|
+
return getRequestContext()?.logger ?? systemLogger;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/run/handlers/nuxt-cache.cts
|
|
115
|
+
var EdgeOneNuxtCacheHandler = class {
|
|
116
|
+
constructor(context) {
|
|
117
|
+
this.context = context;
|
|
118
|
+
}
|
|
119
|
+
memoryCache = /* @__PURE__ */ new Map();
|
|
120
|
+
/**
|
|
121
|
+
* Get cached value by key
|
|
122
|
+
*/
|
|
123
|
+
async get(key, ctx) {
|
|
124
|
+
const logger = getLogger();
|
|
125
|
+
try {
|
|
126
|
+
const memoryEntry = this.memoryCache.get(key);
|
|
127
|
+
if (memoryEntry && memoryEntry.expires > Date.now()) {
|
|
128
|
+
return memoryEntry.value;
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
logger.withError(error).error("Error getting cache value");
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Set cached value by key
|
|
138
|
+
*/
|
|
139
|
+
async set(key, data, ctx) {
|
|
140
|
+
const logger = getLogger();
|
|
141
|
+
try {
|
|
142
|
+
let ttl = 3600;
|
|
143
|
+
if (ctx?.revalidate && typeof ctx.revalidate === "number") {
|
|
144
|
+
ttl = ctx.revalidate;
|
|
145
|
+
} else if ("revalidate" in data && typeof data.revalidate === "number") {
|
|
146
|
+
ttl = data.revalidate;
|
|
147
|
+
}
|
|
148
|
+
this.memoryCache.set(key, {
|
|
149
|
+
value: data,
|
|
150
|
+
expires: Date.now() + ttl * 1e3
|
|
151
|
+
});
|
|
152
|
+
} catch (error) {
|
|
153
|
+
logger.withError(error).error("Error setting cache value");
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Revalidate cache entries by tag
|
|
159
|
+
*/
|
|
160
|
+
async revalidateTag(tag) {
|
|
161
|
+
const logger = getLogger();
|
|
162
|
+
try {
|
|
163
|
+
for (const [key, entry] of this.memoryCache.entries()) {
|
|
164
|
+
if (this.hasTag(entry.value, tag)) {
|
|
165
|
+
this.memoryCache.delete(key);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
logger.log(`Revalidated cache tag: ${tag}`);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
logger.withError(error).error("Error revalidating cache tag");
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Get TTL from cache value
|
|
176
|
+
*/
|
|
177
|
+
getTTL(value) {
|
|
178
|
+
if ("revalidate" in value && typeof value.revalidate === "number") {
|
|
179
|
+
return value.revalidate;
|
|
180
|
+
}
|
|
181
|
+
return 3600;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Check if cache value has specific tag
|
|
185
|
+
*/
|
|
186
|
+
hasTag(value, tag) {
|
|
187
|
+
if ("tags" in value && Array.isArray(value.tags)) {
|
|
188
|
+
return value.tags.includes(tag);
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
function createEdgeOneNuxtCacheHandler(context) {
|
|
194
|
+
return new EdgeOneNuxtCacheHandler(context);
|
|
195
|
+
}
|
|
196
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
197
|
+
0 && (module.exports = {
|
|
198
|
+
EdgeOneNuxtCacheHandler,
|
|
199
|
+
createEdgeOneNuxtCacheHandler
|
|
200
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
|
|
2
|
+
var require = await (async () => {
|
|
3
|
+
var { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
import "../../esm-chunks/chunk-6BT4RYQJ.js";
|
|
8
|
+
|
|
9
|
+
// src/run/handlers/nuxt-server.ts
|
|
10
|
+
var defaultEdgeOneNuxtConfig = {
|
|
11
|
+
// Nuxt specific configuration
|
|
12
|
+
ssr: true,
|
|
13
|
+
nitro: {
|
|
14
|
+
preset: "node-server",
|
|
15
|
+
storage: {}
|
|
16
|
+
},
|
|
17
|
+
experimental: {
|
|
18
|
+
payloadExtraction: false
|
|
19
|
+
},
|
|
20
|
+
// EdgeOne specific settings
|
|
21
|
+
useRegionalBlobs: true,
|
|
22
|
+
cacheControl: {
|
|
23
|
+
maxAge: 3600,
|
|
24
|
+
staleWhileRevalidate: 86400
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function createH3EventFromRequest(request) {
|
|
28
|
+
const url = new URL(request.url);
|
|
29
|
+
const mockReq = {
|
|
30
|
+
method: request.method,
|
|
31
|
+
url: url.pathname + url.search,
|
|
32
|
+
headers: Object.fromEntries(request.headers.entries()),
|
|
33
|
+
body: request.body
|
|
34
|
+
};
|
|
35
|
+
const mockRes = {
|
|
36
|
+
writeHead: () => {
|
|
37
|
+
},
|
|
38
|
+
write: () => {
|
|
39
|
+
},
|
|
40
|
+
end: () => {
|
|
41
|
+
},
|
|
42
|
+
writableEnded: false,
|
|
43
|
+
headersSent: false,
|
|
44
|
+
statusCode: 200,
|
|
45
|
+
statusMessage: "OK",
|
|
46
|
+
_headers: {},
|
|
47
|
+
setHeader: function(name, value) {
|
|
48
|
+
this._headers[name.toLowerCase()] = value;
|
|
49
|
+
},
|
|
50
|
+
getHeader: function(name) {
|
|
51
|
+
return this._headers[name.toLowerCase()];
|
|
52
|
+
},
|
|
53
|
+
removeHeader: function(name) {
|
|
54
|
+
delete this._headers[name.toLowerCase()];
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const event = {
|
|
58
|
+
__is_event__: true,
|
|
59
|
+
node: { req: mockReq, res: mockRes },
|
|
60
|
+
context: {},
|
|
61
|
+
_method: void 0,
|
|
62
|
+
_path: void 0,
|
|
63
|
+
_headers: void 0,
|
|
64
|
+
_requestBody: void 0,
|
|
65
|
+
_handled: false,
|
|
66
|
+
_onBeforeResponseCalled: void 0,
|
|
67
|
+
_onAfterResponseCalled: void 0,
|
|
68
|
+
get method() {
|
|
69
|
+
if (!this._method) {
|
|
70
|
+
this._method = (this.node.req.method || "GET").toUpperCase();
|
|
71
|
+
}
|
|
72
|
+
return this._method;
|
|
73
|
+
},
|
|
74
|
+
get path() {
|
|
75
|
+
return this._path || this.node.req.url || "/";
|
|
76
|
+
},
|
|
77
|
+
get headers() {
|
|
78
|
+
if (!this._headers) {
|
|
79
|
+
this._headers = this._normalizeNodeHeaders(this.node.req.headers);
|
|
80
|
+
}
|
|
81
|
+
return this._headers;
|
|
82
|
+
},
|
|
83
|
+
get handled() {
|
|
84
|
+
return this._handled || this.node.res.writableEnded || this.node.res.headersSent;
|
|
85
|
+
},
|
|
86
|
+
_normalizeNodeHeaders(nodeHeaders) {
|
|
87
|
+
const headers = new Headers();
|
|
88
|
+
for (const [name, value] of Object.entries(nodeHeaders)) {
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
for (const item of value) {
|
|
91
|
+
headers.append(name, item);
|
|
92
|
+
}
|
|
93
|
+
} else if (value) {
|
|
94
|
+
headers.set(name, value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return headers;
|
|
98
|
+
},
|
|
99
|
+
toString() {
|
|
100
|
+
return `[${this.method}] ${this.path}`;
|
|
101
|
+
},
|
|
102
|
+
toJSON() {
|
|
103
|
+
return this.toString();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
return event;
|
|
107
|
+
}
|
|
108
|
+
var EdgeOneNuxtServerHandler = class {
|
|
109
|
+
nuxtHandler = null;
|
|
110
|
+
config;
|
|
111
|
+
nuxtImportPromise;
|
|
112
|
+
constructor(config = defaultEdgeOneNuxtConfig) {
|
|
113
|
+
this.config = { ...defaultEdgeOneNuxtConfig, ...config };
|
|
114
|
+
this.nuxtImportPromise = import(process.cwd() + "/app/.output/server/index.mjs");
|
|
115
|
+
}
|
|
116
|
+
async initializeNuxtServer() {
|
|
117
|
+
if (!this.nuxtHandler) {
|
|
118
|
+
try {
|
|
119
|
+
const nuxtApp = await this.nuxtImportPromise;
|
|
120
|
+
this.nuxtHandler = nuxtApp.default;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error("Failed to initialize Nuxt server:", error);
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async handleRequest(request) {
|
|
128
|
+
try {
|
|
129
|
+
await this.initializeNuxtServer();
|
|
130
|
+
const event = createH3EventFromRequest(request);
|
|
131
|
+
const response = await this.nuxtHandler(event);
|
|
132
|
+
return response;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error("Nuxt handler error:", error);
|
|
135
|
+
return new Response("Internal Server Error", {
|
|
136
|
+
status: 500,
|
|
137
|
+
headers: {
|
|
138
|
+
"Content-Type": "text/plain"
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
function createEdgeOneNuxtServerHandler(config = defaultEdgeOneNuxtConfig) {
|
|
145
|
+
return new EdgeOneNuxtServerHandler(config);
|
|
146
|
+
}
|
|
147
|
+
var nuxt_server_default = async (request) => {
|
|
148
|
+
const handler = createEdgeOneNuxtServerHandler();
|
|
149
|
+
return handler.handleRequest(request);
|
|
150
|
+
};
|
|
151
|
+
export {
|
|
152
|
+
EdgeOneNuxtServerHandler,
|
|
153
|
+
createEdgeOneNuxtServerHandler,
|
|
154
|
+
nuxt_server_default as default,
|
|
155
|
+
defaultEdgeOneNuxtConfig
|
|
156
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/run/handlers/request-context.cts
|
|
21
|
+
var request_context_exports = {};
|
|
22
|
+
__export(request_context_exports, {
|
|
23
|
+
createRequestContext: () => createRequestContext,
|
|
24
|
+
getLogger: () => getLogger,
|
|
25
|
+
getRequestContext: () => getRequestContext,
|
|
26
|
+
runWithRequestContext: () => runWithRequestContext
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(request_context_exports);
|
|
29
|
+
var import_node_async_hooks = require("node:async_hooks");
|
|
30
|
+
|
|
31
|
+
// node_modules/@netlify/functions/dist/internal.js
|
|
32
|
+
var import_process = require("process");
|
|
33
|
+
var systemLogTag = "__nfSystemLog";
|
|
34
|
+
var serializeError = (error) => {
|
|
35
|
+
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
36
|
+
return {
|
|
37
|
+
error: error.message,
|
|
38
|
+
error_cause: cause,
|
|
39
|
+
error_stack: error.stack
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
43
|
+
LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
|
|
44
|
+
LogLevel2[LogLevel2["Log"] = 2] = "Log";
|
|
45
|
+
LogLevel2[LogLevel2["Error"] = 3] = "Error";
|
|
46
|
+
return LogLevel2;
|
|
47
|
+
})(LogLevel || {});
|
|
48
|
+
var SystemLogger = class _SystemLogger {
|
|
49
|
+
fields;
|
|
50
|
+
logLevel;
|
|
51
|
+
constructor(fields = {}, logLevel = 2) {
|
|
52
|
+
this.fields = fields;
|
|
53
|
+
this.logLevel = logLevel;
|
|
54
|
+
}
|
|
55
|
+
doLog(logger, message) {
|
|
56
|
+
if (import_process.env.NETLIFY_DEV && !import_process.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
60
|
+
}
|
|
61
|
+
log(message) {
|
|
62
|
+
if (this.logLevel > 2) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.doLog(console.log, message);
|
|
66
|
+
}
|
|
67
|
+
debug(message) {
|
|
68
|
+
if (this.logLevel > 1) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.doLog(console.debug, message);
|
|
72
|
+
}
|
|
73
|
+
error(message) {
|
|
74
|
+
if (this.logLevel > 3) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.doLog(console.error, message);
|
|
78
|
+
}
|
|
79
|
+
withLogLevel(level) {
|
|
80
|
+
return new _SystemLogger(this.fields, level);
|
|
81
|
+
}
|
|
82
|
+
withFields(fields) {
|
|
83
|
+
return new _SystemLogger(
|
|
84
|
+
{
|
|
85
|
+
...this.fields,
|
|
86
|
+
...fields
|
|
87
|
+
},
|
|
88
|
+
this.logLevel
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
withError(error) {
|
|
92
|
+
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
93
|
+
return this.withFields(fields);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var systemLogger = new SystemLogger();
|
|
97
|
+
|
|
98
|
+
// src/run/handlers/request-context.cts
|
|
99
|
+
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
100
|
+
var REQUEST_COUNTER_KEY = Symbol.for("nf-request-counter");
|
|
101
|
+
var extendedGlobalThis = globalThis;
|
|
102
|
+
function createRequestContext(request, context) {
|
|
103
|
+
const backgroundWorkPromises = [];
|
|
104
|
+
const logger = systemLogger.withLogLevel(LogLevel.Log);
|
|
105
|
+
return {
|
|
106
|
+
isBackgroundRevalidation: false,
|
|
107
|
+
captureServerTiming: false,
|
|
108
|
+
trackBackgroundWork: (promise) => {
|
|
109
|
+
if (context?.waitUntil) {
|
|
110
|
+
context.waitUntil(promise);
|
|
111
|
+
} else {
|
|
112
|
+
backgroundWorkPromises.push(promise);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
get backgroundWorkPromise() {
|
|
116
|
+
return Promise.allSettled(backgroundWorkPromises);
|
|
117
|
+
},
|
|
118
|
+
logger,
|
|
119
|
+
requestID: ""
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
var requestContextAsyncLocalStorage;
|
|
123
|
+
function getRequestContextAsyncLocalStorage() {
|
|
124
|
+
if (requestContextAsyncLocalStorage) {
|
|
125
|
+
return requestContextAsyncLocalStorage;
|
|
126
|
+
}
|
|
127
|
+
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
128
|
+
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
129
|
+
}
|
|
130
|
+
const storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
131
|
+
requestContextAsyncLocalStorage = storage;
|
|
132
|
+
extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
|
|
133
|
+
return storage;
|
|
134
|
+
}
|
|
135
|
+
var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
136
|
+
function runWithRequestContext(requestContext, fn) {
|
|
137
|
+
return getRequestContextAsyncLocalStorage().run(requestContext, fn);
|
|
138
|
+
}
|
|
139
|
+
function getLogger() {
|
|
140
|
+
return getRequestContext()?.logger ?? systemLogger;
|
|
141
|
+
}
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {
|
|
144
|
+
createRequestContext,
|
|
145
|
+
getLogger,
|
|
146
|
+
getRequestContext,
|
|
147
|
+
runWithRequestContext
|
|
148
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
|
|
2
|
+
var require = await (async () => {
|
|
3
|
+
var { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
getTracer
|
|
9
|
+
} from "../../esm-chunks/chunk-UOPC2N5A.js";
|
|
10
|
+
import "../../esm-chunks/chunk-V2LFVP3C.js";
|
|
11
|
+
import {
|
|
12
|
+
getRunConfig,
|
|
13
|
+
setFetchBeforeNuxtPatchedIt,
|
|
14
|
+
setRunConfig
|
|
15
|
+
} from "../../esm-chunks/chunk-HY3HNABZ.js";
|
|
16
|
+
import {
|
|
17
|
+
getLogger,
|
|
18
|
+
getRequestContext
|
|
19
|
+
} from "../../esm-chunks/chunk-KGYBHZC3.js";
|
|
20
|
+
import "../../esm-chunks/chunk-HBXUWFGE.js";
|
|
21
|
+
import {
|
|
22
|
+
setCacheControlHeaders,
|
|
23
|
+
setCacheStatusHeader
|
|
24
|
+
} from "../../esm-chunks/chunk-5YBUNNZ4.js";
|
|
25
|
+
import "../../esm-chunks/chunk-6BT4RYQJ.js";
|
|
26
|
+
|
|
27
|
+
// src/run/handlers/wait-until.cts
|
|
28
|
+
var NEXT_REQUEST_CONTEXT_SYMBOL = Symbol.for("@next/request-context");
|
|
29
|
+
function setupWaitUntil() {
|
|
30
|
+
;
|
|
31
|
+
globalThis[NEXT_REQUEST_CONTEXT_SYMBOL] = {
|
|
32
|
+
get() {
|
|
33
|
+
return { waitUntil: getRequestContext()?.trackBackgroundWork };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/run/handlers/server.ts
|
|
39
|
+
setFetchBeforeNuxtPatchedIt(globalThis.fetch);
|
|
40
|
+
var { nextConfig, nuxtConfig } = await getRunConfig();
|
|
41
|
+
setRunConfig(nextConfig);
|
|
42
|
+
setupWaitUntil();
|
|
43
|
+
var nuxtImportPromise = import(process.cwd() + "/app/.output/server/index.mjs");
|
|
44
|
+
var nuxtHandler;
|
|
45
|
+
var server_default = async (request, _context, topLevelSpan, requestContext) => {
|
|
46
|
+
const tracer = getTracer();
|
|
47
|
+
if (!nuxtHandler) {
|
|
48
|
+
await tracer.withActiveSpan("initialize nuxt server", async () => {
|
|
49
|
+
const nuxtApp = await nuxtImportPromise;
|
|
50
|
+
nuxtHandler = nuxtApp.default;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return await tracer.withActiveSpan("generate response", async (span) => {
|
|
54
|
+
try {
|
|
55
|
+
const response = await nuxtHandler(request);
|
|
56
|
+
if (requestContext.responseCacheKey) {
|
|
57
|
+
topLevelSpan.setAttribute("responseCacheKey", requestContext.responseCacheKey);
|
|
58
|
+
}
|
|
59
|
+
setCacheControlHeaders(response, request, requestContext);
|
|
60
|
+
setCacheStatusHeader(response.headers, null);
|
|
61
|
+
return response;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
getLogger().withError(error).error("nuxt handler error");
|
|
64
|
+
console.error(error);
|
|
65
|
+
span.setAttribute("http.status_code", 500);
|
|
66
|
+
return new Response("Internal Server Error", {
|
|
67
|
+
status: 500,
|
|
68
|
+
headers: {
|
|
69
|
+
"Content-Type": "text/plain"
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
server_default as default
|
|
77
|
+
};
|