@harlan-zw/nuxt-cloudflare 0.5.1 → 0.5.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.
- package/dist/module.json +1 -1
- package/dist/module.mjs +5 -0
- package/dist/runtime/server/nitro-alias.d.ts +1 -0
- package/dist/runtime/server/nitro2.d.ts +2 -0
- package/dist/runtime/server/nitro2.js +1 -0
- package/dist/runtime/server/nitro3.d.ts +2 -0
- package/dist/runtime/server/nitro3.js +1 -0
- package/dist/runtime/server/plugins/request-lifetime.d.ts +10 -0
- package/dist/runtime/server/plugins/request-lifetime.js +7 -0
- package/dist/runtime/server/utils/request-lifetime.d.ts +23 -0
- package/dist/runtime/server/utils/request-lifetime.js +7 -0
- package/package.json +8 -8
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -110,6 +110,10 @@ const runtimeConfigPluginPath = resolve(
|
|
|
110
110
|
import.meta.dirname,
|
|
111
111
|
import.meta.url.endsWith(".ts") ? "runtime/server/plugins/runtime-config.ts" : "runtime/server/plugins/runtime-config.js"
|
|
112
112
|
);
|
|
113
|
+
const requestLifetimePluginPath = resolve(
|
|
114
|
+
import.meta.dirname,
|
|
115
|
+
import.meta.url.endsWith(".ts") ? "runtime/server/plugins/request-lifetime.ts" : "runtime/server/plugins/request-lifetime.js"
|
|
116
|
+
);
|
|
113
117
|
const WIDE_EVENT_FIELDS = [
|
|
114
118
|
"cf.colo",
|
|
115
119
|
"cf.country",
|
|
@@ -173,6 +177,7 @@ function configureNitroCloudflare(nitro, options, context = {}) {
|
|
|
173
177
|
workersCache: resolveModuleWorkersCachePolicy(options)
|
|
174
178
|
}, authored._tag === "authored" ? authored.config : {});
|
|
175
179
|
addNitroPlugin(nitro, runtimeConfigPluginPath);
|
|
180
|
+
addNitroPlugin(nitro, requestLifetimePluginPath);
|
|
176
181
|
if (nitro.cloudflare.wrangler.cache?.enabled)
|
|
177
182
|
addNitroPlugin(nitro, workersCachePluginPath);
|
|
178
183
|
if (options.kvCache === false)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare module '#nuxt-cloudflare/nitro' {
|
|
2
2
|
export const defineNitroPlugin: typeof import('./nitro2').defineNitroPlugin
|
|
3
|
+
export const defineNitroAppPlugin: typeof import('./nitro2').defineNitroAppPlugin
|
|
3
4
|
export const useRuntimeConfig: typeof import('./nitro2').useRuntimeConfig
|
|
4
5
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { NitroAppPlugin } from 'nitropack/types';
|
|
2
2
|
export { useRuntimeConfig } from 'nitropack/runtime';
|
|
3
|
+
/** Registers a plugin that receives the Nitro app itself, not the hook-adapted copy. */
|
|
4
|
+
export declare const defineNitroAppPlugin: (setup: NitroAppPlugin) => NitroAppPlugin;
|
|
3
5
|
export declare function defineNitroPlugin(setup: NitroAppPlugin): NitroAppPlugin;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineNitroPlugin as definePlugin } from "nitropack/runtime";
|
|
2
2
|
export { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
export const defineNitroAppPlugin = definePlugin;
|
|
3
4
|
export function defineNitroPlugin(setup) {
|
|
4
5
|
return definePlugin((app) => {
|
|
5
6
|
const hooks = app.hooks;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { NitroAppPlugin } from 'nitro/types';
|
|
2
2
|
export { useRuntimeConfig } from 'nuxt/server';
|
|
3
|
+
/** Registers a plugin that receives the Nitro app itself, not the hook-adapted copy. */
|
|
4
|
+
export declare const defineNitroAppPlugin: (setup: NitroAppPlugin) => NitroAppPlugin;
|
|
3
5
|
export declare function defineNitroPlugin(setup: NitroAppPlugin): NitroAppPlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps each Worker request alive until its response settles, so a visitor who
|
|
3
|
+
* leaves cannot strand a promise that later requests share.
|
|
4
|
+
*
|
|
5
|
+
* Nitro's Cloudflare entry reads `nitroApp.localFetch` on every request, so the
|
|
6
|
+
* wrapper must replace it on the app itself. An app without `localFetch`, such
|
|
7
|
+
* as Nitro 3, is left unchanged.
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: any;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { defineNitroAppPlugin } from "#nuxt-cloudflare/nitro";
|
|
2
|
+
import { keepRequestAlive } from "../utils/request-lifetime.js";
|
|
3
|
+
export default defineNitroAppPlugin((nitroApp) => {
|
|
4
|
+
const app = nitroApp;
|
|
5
|
+
if (typeof app.localFetch === "function")
|
|
6
|
+
app.localFetch = keepRequestAlive(app.localFetch);
|
|
7
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The Worker context Nitro's Cloudflare entry passes to `localFetch`. */
|
|
2
|
+
export interface LocalFetchInit {
|
|
3
|
+
context?: {
|
|
4
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
/** Nitro 2's in-process fetch, `nitroApp.localFetch`. */
|
|
8
|
+
export type LocalFetch = (input: string, init?: LocalFetchInit) => Promise<Response>;
|
|
9
|
+
/**
|
|
10
|
+
* Wraps Nitro's `localFetch` so each Worker request stays alive until its own
|
|
11
|
+
* response settles.
|
|
12
|
+
*
|
|
13
|
+
* Nitro's cached functions and Nuxt Content share one in-flight promise per key
|
|
14
|
+
* across every request in an isolate. On Workers a promise can only settle in
|
|
15
|
+
* the request that created it. When a visitor leaves, Cloudflare cancels that
|
|
16
|
+
* request, the shared promise can never settle, and every later request for the
|
|
17
|
+
* key fails. Registering the response with `waitUntil` keeps the creating
|
|
18
|
+
* request alive for up to 30 seconds after its client disconnects.
|
|
19
|
+
*
|
|
20
|
+
* A fetch without a Worker context, such as an internal `$fetch` outside a
|
|
21
|
+
* request, passes through unchanged.
|
|
22
|
+
*/
|
|
23
|
+
export declare function keepRequestAlive(localFetch: LocalFetch): LocalFetch;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harlan-zw/nuxt-cloudflare",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"description": "Opinionated Cloudflare deployment defaults and diagnostics for Nuxt.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -116,25 +116,25 @@
|
|
|
116
116
|
}
|
|
117
117
|
},
|
|
118
118
|
"dependencies": {
|
|
119
|
-
"@nuxt/kit": "^4.6.
|
|
119
|
+
"@nuxt/kit": "^4.6.4",
|
|
120
120
|
"citty": "^0.2.2",
|
|
121
121
|
"confbox": "^0.2.4",
|
|
122
122
|
"consola": "^3.4.2",
|
|
123
123
|
"h3": "2.0.1-rc.25",
|
|
124
|
-
"nitropack": "^2.13.
|
|
124
|
+
"nitropack": "^2.13.6",
|
|
125
125
|
"pathe": "^2.0.3",
|
|
126
|
-
"unstorage": "^1.17.
|
|
126
|
+
"unstorage": "^1.17.6"
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
129
|
"@antfu/eslint-config": "^9.3.0",
|
|
130
130
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
131
131
|
"@cloudflare/workers-types": "^5.20260811.1",
|
|
132
132
|
"@nuxt/module-builder": "^1.0.2",
|
|
133
|
-
"@nuxt/schema": "^4.6.
|
|
134
|
-
"@types/node": "^26.
|
|
135
|
-
"eslint": "^10.
|
|
133
|
+
"@nuxt/schema": "^4.6.4",
|
|
134
|
+
"@types/node": "^26.6.6",
|
|
135
|
+
"eslint": "^10.15.0",
|
|
136
136
|
"nitro": "3.0.260903-beta",
|
|
137
|
-
"nuxt": "^4.6.
|
|
137
|
+
"nuxt": "^4.6.4",
|
|
138
138
|
"typescript": "^5.9.3",
|
|
139
139
|
"unbuild": "^3.6.1",
|
|
140
140
|
"vitest": "^4.1.10",
|