nitro-nightly 3.0.1-20260108-220050-08740398 → 3.0.1-20260109-100347-99691fcb

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.
@@ -1,6 +1,6 @@
1
1
  import "#nitro/virtual/polyfills";
2
2
  import type * as CF from "@cloudflare/workers-types";
3
- import type { ExportedHandler } from "@cloudflare/workers-types";
3
+ import type { ServerRuntimeContext } from "srvx";
4
4
  type MaybePromise<T> = T | Promise<T>;
5
5
  export declare function createHandler<Env>(hooks: {
6
6
  fetch: (...params: [...Parameters<NonNullable<ExportedHandler<Env>["fetch"]>>, url: URL, cfContextExtras: any]) => MaybePromise<Response | CF.Response | undefined>;
@@ -12,5 +12,5 @@ export declare function createHandler<Env>(hooks: {
12
12
  tail(traces, env, context);
13
13
  trace(traces, env, context);
14
14
  };
15
- export declare function fetchHandler(cfReq: Request | CF.Request, env: unknown, context: CF.ExecutionContext | DurableObjectState, url: URL, nitroApp, ctxExt: any);
15
+ export declare function augmentReq(cfReq: Request | CF.Request, ctx: NonNullable<ServerRuntimeContext["cloudflare"]>);
16
16
  export {};
@@ -6,6 +6,11 @@ export function createHandler(hooks) {
6
6
  const nitroHooks = useNitroHooks();
7
7
  return {
8
8
  async fetch(request, env, context) {
9
+ globalThis.__env__ = env;
10
+ augmentReq(request, {
11
+ env,
12
+ context
13
+ });
9
14
  const ctxExt = {};
10
15
  const url = new URL(request.url);
11
16
  // Preset-specific logic
@@ -15,7 +20,7 @@ export function createHandler(hooks) {
15
20
  return res;
16
21
  }
17
22
  }
18
- return fetchHandler(request, env, context, url, nitroApp, ctxExt);
23
+ return await nitroApp.fetch(request);
19
24
  },
20
25
  scheduled(controller, env, context) {
21
26
  globalThis.__env__ = env;
@@ -70,16 +75,12 @@ export function createHandler(hooks) {
70
75
  }
71
76
  };
72
77
  }
73
- export async function fetchHandler(cfReq, env, context, url = new URL(cfReq.url), nitroApp = useNitroApp(), ctxExt) {
74
- // Expose latest env to the global context
75
- globalThis.__env__ = env;
76
- // srvx compatibility
78
+ export function augmentReq(cfReq, ctx) {
77
79
  const req = cfReq;
78
80
  req.runtime ??= { name: "cloudflare" };
79
- req.runtime.cloudflare ??= {
80
- context,
81
- env
81
+ req.runtime.cloudflare = {
82
+ ...req.runtime.cloudflare,
83
+ ...ctx
82
84
  };
83
- req.waitUntil = context.waitUntil.bind(context);
84
- return nitroApp.fetch(req);
85
+ req.waitUntil = ctx.context?.waitUntil.bind(ctx.context);
85
86
  }
@@ -1,7 +1,7 @@
1
1
  import "#nitro/virtual/polyfills";
2
2
  import { DurableObject } from "cloudflare:workers";
3
3
  import wsAdapter from "crossws/adapters/cloudflare";
4
- import { createHandler, fetchHandler } from "./_module-handler.mjs";
4
+ import { createHandler, augmentReq } from "./_module-handler.mjs";
5
5
  import { useNitroApp, useNitroHooks } from "nitro/app";
6
6
  import { isPublicAssetURL } from "#nitro/virtual/public-assets";
7
7
  import { resolveWebsocketHooks } from "#nitro/runtime/app";
@@ -48,12 +48,14 @@ export class $DurableObject extends DurableObject {
48
48
  }
49
49
  }
50
50
  fetch(request) {
51
+ augmentReq(request, {
52
+ env: this.env,
53
+ context: this.ctx
54
+ });
51
55
  if (hasWebSocket && request.headers.get("upgrade") === "websocket") {
52
56
  return ws.handleDurableUpgrade(this, request);
53
57
  }
54
- // Main handler
55
- const url = new URL(request.url);
56
- return fetchHandler(request, this.env, this.ctx, url, nitroApp, { durable: this });
58
+ return nitroApp.fetch(request);
57
59
  }
58
60
  alarm() {
59
61
  this.ctx.waitUntil(nitroHooks.callHook("cloudflare:durable:alarm", this) || Promise.resolve());
@@ -5,14 +5,14 @@ import { createHandler } from "./_module-handler.mjs";
5
5
  import { resolveWebsocketHooks } from "#nitro/runtime/app";
6
6
  import { hasWebSocket } from "#nitro/virtual/feature-flags";
7
7
  const ws = hasWebSocket ? wsAdapter({ resolve: resolveWebsocketHooks }) : undefined;
8
- export default createHandler({ fetch(request, env, context, url) {
8
+ export default createHandler({ fetch(cfRequest, env, context, url) {
9
9
  // Static assets fallback (optional binding)
10
10
  if (env.ASSETS && isPublicAssetURL(url.pathname)) {
11
- return env.ASSETS.fetch(request);
11
+ return env.ASSETS.fetch(cfRequest);
12
12
  }
13
13
  // Websocket upgrade
14
14
  // https://crossws.unjs.io/adapters/cloudflare
15
- if (hasWebSocket && request.headers.get("upgrade") === "websocket") {
16
- return ws.handleUpgrade(request, env, context);
15
+ if (hasWebSocket && cfRequest.headers.get("upgrade") === "websocket") {
16
+ return ws.handleUpgrade(cfRequest, env, context);
17
17
  }
18
18
  } });
@@ -5,18 +5,15 @@ import { isPublicAssetURL } from "#nitro/virtual/public-assets";
5
5
  import { runCronTasks } from "#nitro/runtime/task";
6
6
  import { resolveWebsocketHooks } from "#nitro/runtime/app";
7
7
  import { hasWebSocket } from "#nitro/virtual/feature-flags";
8
+ import { augmentReq } from "./_module-handler.mjs";
8
9
  const nitroApp = useNitroApp();
9
10
  const ws = hasWebSocket ? wsAdapter({ resolve: resolveWebsocketHooks }) : undefined;
10
11
  export default {
11
12
  async fetch(cfReq, env, context) {
12
- // srvx compatibility
13
- const req = cfReq;
14
- req.runtime ??= { name: "cloudflare" };
15
- req.runtime.cloudflare ??= {
16
- context,
17
- env
18
- };
19
- req.waitUntil = context.waitUntil.bind(context);
13
+ augmentReq(cfReq, {
14
+ env,
15
+ context
16
+ });
20
17
  // Websocket upgrade
21
18
  // https://crossws.unjs.io/adapters/cloudflare
22
19
  if (hasWebSocket && cfReq.headers.get("upgrade") === "websocket") {
@@ -26,9 +23,7 @@ export default {
26
23
  if (env.ASSETS && isPublicAssetURL(url.pathname)) {
27
24
  return env.ASSETS.fetch(cfReq);
28
25
  }
29
- // Expose latest env to the global context
30
- globalThis.__env__ = env;
31
- return nitroApp.fetch(req);
26
+ return nitroApp.fetch(cfReq);
32
27
  },
33
28
  scheduled(event, env, context) {
34
29
  if (import.meta._tasks) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitro-nightly",
3
- "version": "3.0.1-20260108-220050-08740398",
3
+ "version": "3.0.1-20260109-100347-99691fcb",
4
4
  "description": "Build and Deploy Universal JavaScript Servers",
5
5
  "homepage": "https://nitro.build",
6
6
  "repository": "nitrojs/nitro",