@vesk/adapter 0.2.87 → 0.2.89
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/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +82 -12
- package/dist/platform-handler.d.ts.map +1 -1
- package/dist/platform-handler.js +15 -3
- package/package.json +4 -4
package/dist/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAA2B,MAAM,yBAAyB,CAAC;AAS5F,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAA2B,MAAM,yBAAyB,CAAC;AAS5F,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAmFhG;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAiF5E"}
|
package/dist/middleware.js
CHANGED
|
@@ -41,13 +41,48 @@ export function compileMiddleware(mwChain, _appDir) {
|
|
|
41
41
|
' nextResult = await run(index + 1);',
|
|
42
42
|
' return nextResult;',
|
|
43
43
|
' }',
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'
|
|
44
|
+
' try {',
|
|
45
|
+
' const result = await fn(ctx, next);',
|
|
46
|
+
' if (result instanceof Response) return result;',
|
|
47
|
+
' if (nextResult instanceof Response) return nextResult;',
|
|
48
|
+
' if (!nextCalled) return run(index + 1);',
|
|
49
|
+
' return null;',
|
|
50
|
+
' } catch (e) {',
|
|
51
|
+
' if (e && typeof e === \'object\' && e.name === \'Redirect\') {',
|
|
52
|
+
' return new Response(null, {',
|
|
53
|
+
' status: Number(e.status) || 302,',
|
|
54
|
+
' headers: { Location: String(e.url || \'\') },',
|
|
55
|
+
' });',
|
|
56
|
+
' }',
|
|
57
|
+
' if (e instanceof TypeError && /Failed to parse URL from/.test(String(e.message))) {',
|
|
58
|
+
' const msg = String(e.message);',
|
|
59
|
+
' const prefix = \'Failed to parse URL from \';',
|
|
60
|
+
' const start = msg.indexOf(prefix);',
|
|
61
|
+
' const target = start === -1 ? \'\' : msg.slice(start + prefix.length).trim().split(\' \')[0];',
|
|
62
|
+
' return new Response(null, { status: 302, headers: { Location: target } });',
|
|
63
|
+
' }',
|
|
64
|
+
' // Any other TypeError from the middleware (e.g. reading a property of',
|
|
65
|
+
' // `undefined` like `ctx.cookies[SESSION_COOKIE]` when `ctx.cookies` is',
|
|
66
|
+
' // missing) must not crash the server. On serverless platforms (Vercel,',
|
|
67
|
+
' // Netlify, Cloudflare) an uncaught throw surfaces as',
|
|
68
|
+
' // FUNCTION_INVOCATION_FAILED — Next.js avoids this by wrapping entry',
|
|
69
|
+
' // points the same way. Return a 500 instead.',
|
|
70
|
+
' if (e instanceof TypeError) {',
|
|
71
|
+
' return new Response(null, { status: 500 });',
|
|
72
|
+
' }',
|
|
73
|
+
' throw e;',
|
|
74
|
+
' }',
|
|
75
|
+
' }',
|
|
76
|
+
' let response = null;',
|
|
77
|
+
' try {',
|
|
78
|
+
' response = await run(0);',
|
|
79
|
+
' } catch (e) {',
|
|
80
|
+
' // Unexpected middleware errors must not crash the server. On serverless',
|
|
81
|
+
' // platforms (Vercel, Netlify, Cloudflare) an uncaught throw surfaces as',
|
|
82
|
+
' // FUNCTION_INVOCATION_FAILED — Next.js avoids this by wrapping entry',
|
|
83
|
+
' // points the same way. Convert it into a 500 response.',
|
|
84
|
+
' response = new Response(null, { status: 500 });',
|
|
49
85
|
' }',
|
|
50
|
-
' const response = await run(0);',
|
|
51
86
|
' return { response, rewriteUrl };',
|
|
52
87
|
'}',
|
|
53
88
|
'',
|
|
@@ -87,13 +122,48 @@ export function compileMiddlewareCode(mwSourceTexts) {
|
|
|
87
122
|
' ncResult = await run(index + 1);',
|
|
88
123
|
' return ncResult;',
|
|
89
124
|
' }',
|
|
90
|
-
'
|
|
91
|
-
'
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
'
|
|
125
|
+
' try {',
|
|
126
|
+
' const result = await fn(ctx, next);',
|
|
127
|
+
' if (result instanceof Response) return result;',
|
|
128
|
+
' if (ncResult instanceof Response) return ncResult;',
|
|
129
|
+
' if (!nc) return run(index + 1);',
|
|
130
|
+
' return null;',
|
|
131
|
+
' } catch (e) {',
|
|
132
|
+
' if (e && typeof e === \'object\' && e.name === \'Redirect\') {',
|
|
133
|
+
' return new Response(null, {',
|
|
134
|
+
' status: Number(e.status) || 302,',
|
|
135
|
+
' headers: { Location: String(e.url || \'\') },',
|
|
136
|
+
' });',
|
|
137
|
+
' }',
|
|
138
|
+
' if (e instanceof TypeError && /Failed to parse URL from/.test(String(e.message))) {',
|
|
139
|
+
' const msg = String(e.message);',
|
|
140
|
+
' const prefix = \'Failed to parse URL from \';',
|
|
141
|
+
' const start = msg.indexOf(prefix);',
|
|
142
|
+
' const target = start === -1 ? \'\' : msg.slice(start + prefix.length).trim().split(\' \')[0];',
|
|
143
|
+
' return new Response(null, { status: 302, headers: { Location: target } });',
|
|
144
|
+
' }',
|
|
145
|
+
' // Any other TypeError from the middleware (e.g. reading a property of',
|
|
146
|
+
' // `undefined` like `ctx.cookies[SESSION_COOKIE]` when `ctx.cookies` is',
|
|
147
|
+
' // missing) must not crash the server. On serverless platforms (Vercel,',
|
|
148
|
+
' // Netlify, Cloudflare) an uncaught throw surfaces as',
|
|
149
|
+
' // FUNCTION_INVOCATION_FAILED — Next.js avoids this by wrapping entry',
|
|
150
|
+
' // points the same way. Return a 500 instead.',
|
|
151
|
+
' if (e instanceof TypeError) {',
|
|
152
|
+
' return new Response(null, { status: 500 });',
|
|
153
|
+
' }',
|
|
154
|
+
' throw e;',
|
|
155
|
+
' }',
|
|
156
|
+
' }',
|
|
157
|
+
' let response = null;',
|
|
158
|
+
' try {',
|
|
159
|
+
' response = await run(0);',
|
|
160
|
+
' } catch (e) {',
|
|
161
|
+
' // Unexpected middleware errors must not crash the server. On serverless',
|
|
162
|
+
' // platforms (Vercel, Netlify, Cloudflare) an uncaught throw surfaces as',
|
|
163
|
+
' // FUNCTION_INVOCATION_FAILED — Next.js avoids this by wrapping entry',
|
|
164
|
+
' // points the same way. Convert it into a 500 response.',
|
|
165
|
+
' response = new Response(null, { status: 500 });',
|
|
95
166
|
' }',
|
|
96
|
-
' const response = await run(0);',
|
|
97
167
|
' return { response, rewriteUrl };',
|
|
98
168
|
'}',
|
|
99
169
|
'',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-handler.d.ts","sourceRoot":"","sources":["../src/platform-handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AASvE,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAMpD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC;AAgBD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"platform-handler.d.ts","sourceRoot":"","sources":["../src/platform-handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AASvE,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAMpD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGrD;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEtC;AAgBD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CA8OjF;AAED,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4GzF;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
|
package/dist/platform-handler.js
CHANGED
|
@@ -151,9 +151,10 @@ function __matchPath(pattern, pathname) {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
export async function handleRequest(request) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
try {
|
|
155
|
+
const url = new URL(request.url);
|
|
156
|
+
const pathname = url.pathname;
|
|
157
|
+
const isDataRequest = request.headers.get('x-vesk-data') === '1';
|
|
157
158
|
${serverStoreLine}
|
|
158
159
|
|
|
159
160
|
if (__prerendered.has(pathname) && !isDataRequest) {
|
|
@@ -248,6 +249,17 @@ ${eventsRequestLine}
|
|
|
248
249
|
status: 404,
|
|
249
250
|
headers: { 'Content-Type': 'text/html' },
|
|
250
251
|
});
|
|
252
|
+
} catch (e) {
|
|
253
|
+
// Any error that escapes the route (a thrown exception, a bad import, a
|
|
254
|
+
// middleware failure, ...) must not bubble out of handleRequest. On
|
|
255
|
+
// serverless platforms (Vercel, Netlify, Cloudflare) an uncaught throw is
|
|
256
|
+
// surfaced as FUNCTION_INVOCATION_FAILED — Next.js avoids this by wrapping
|
|
257
|
+
// its entry points the same way. Convert it into a proper 500 response.
|
|
258
|
+
return new Response(renderDefaultErrorPage({ url: request.url }), {
|
|
259
|
+
status: 500,
|
|
260
|
+
headers: { 'Content-Type': 'text/html' },
|
|
261
|
+
});
|
|
262
|
+
}
|
|
251
263
|
}
|
|
252
264
|
`;
|
|
253
265
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vesk/adapter",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.89",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Vesk adapter — builds deployable .vesk/ output for Deno and Node serverless",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"sharp": "^0.35.3"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@vesk/compiler": "^0.2.
|
|
27
|
-
"@vesk/runtime": "^0.2.
|
|
28
|
-
"@vesk/types": "^0.2.
|
|
26
|
+
"@vesk/compiler": "^0.2.89",
|
|
27
|
+
"@vesk/runtime": "^0.2.89",
|
|
28
|
+
"@vesk/types": "^0.2.89"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/ws": "^8.18.1",
|