nitropack-nightly 2.11.3-20250306-111821.d219707f → 2.11.4-20250306-152741.e20071e0

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.
@@ -2445,7 +2445,7 @@ async function defaultHandler(error, event, opts) {
2445
2445
  "content-security-policy": "script-src 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self';"
2446
2446
  };
2447
2447
  if (statusCode === 404 || !getResponseHeader(event, "cache-control")) {
2448
- headers["Cache-Control"] = "no-cache";
2448
+ headers["cache-control"] = "no-cache";
2449
2449
  }
2450
2450
  const body = useJSON ? {
2451
2451
  error: true,
@@ -1,3 +1,3 @@
1
- const version = "2.11.3-20250306-111821.d219707f";
1
+ const version = "2.11.4-20250306-152741.e20071e0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "2.11.3-20250306-111821.d219707f";
1
+ const version = "2.11.4-20250306-152741.e20071e0";
2
2
 
3
3
  export { version };
@@ -1,3 +1,3 @@
1
- const version = "2.11.3-20250306-111821.d219707f";
1
+ const version = "2.11.4-20250306-152741.e20071e0";
2
2
 
3
3
  export { version };
@@ -20,38 +20,26 @@ const {
20
20
  NITRO_DEV_WORKER_DIR = ".",
21
21
  NITRO_DEV_WORKER_ID
22
22
  } = process.env;
23
+ trapUnhandledNodeErrors();
24
+ parentPort?.on("message", (msg) => {
25
+ if (msg && msg.event === "shutdown") {
26
+ shutdown();
27
+ }
28
+ });
23
29
  const nitroApp = useNitroApp();
24
30
  const server = new Server(toNodeListener(nitroApp.h3App));
31
+ let listener;
32
+ listen().catch(() => listen(
33
+ true
34
+ /* use random port */
35
+ )).catch((error) => {
36
+ console.error("Dev worker failed to listen:", error);
37
+ return shutdown();
38
+ });
25
39
  if (import.meta._websocket) {
26
40
  const { handleUpgrade } = wsAdapter(nitroApp.h3App.websocket);
27
41
  server.on("upgrade", handleUpgrade);
28
42
  }
29
- function getAddress() {
30
- if (NITRO_NO_UNIX_SOCKET || process.versions.webcontainer) {
31
- return 0;
32
- }
33
- const socketName = `worker-${process.pid}-${threadId}-${Math.round(Math.random() * 1e4)}-${NITRO_DEV_WORKER_ID}.sock`;
34
- const socketPath = join(NITRO_DEV_WORKER_DIR, socketName);
35
- switch (process.platform) {
36
- case "win32": {
37
- return join(String.raw`\\.\pipe\nitro`, socketPath);
38
- }
39
- case "linux": {
40
- return `\0${socketPath}`;
41
- }
42
- default: {
43
- return socketPath;
44
- }
45
- }
46
- }
47
- const listenAddress = getAddress();
48
- const listener = server.listen(listenAddress, () => {
49
- const _address = server.address();
50
- parentPort?.postMessage({
51
- event: "listen",
52
- address: typeof _address === "string" ? { socketPath: _address } : { host: "localhost", port: _address?.port }
53
- });
54
- });
55
43
  nitroApp.router.get(
56
44
  "/_nitro/tasks",
57
45
  defineEventHandler(async (event) => {
@@ -78,20 +66,47 @@ nitroApp.router.use(
78
66
  return await runTask(name, { payload });
79
67
  })
80
68
  );
81
- trapUnhandledNodeErrors();
82
- async function onShutdown() {
69
+ if (import.meta._tasks) {
70
+ startScheduleRunner();
71
+ }
72
+ function listen(useRandomPort = Boolean(
73
+ NITRO_NO_UNIX_SOCKET || process.versions.webcontainer
74
+ )) {
75
+ return new Promise((resolve, reject) => {
76
+ try {
77
+ listener = server.listen(useRandomPort ? 0 : getSocketAddress(), () => {
78
+ const address = server.address();
79
+ parentPort?.postMessage({
80
+ event: "listen",
81
+ address: typeof address === "string" ? { socketPath: address } : { host: "localhost", port: address?.port }
82
+ });
83
+ resolve();
84
+ });
85
+ } catch (error) {
86
+ reject(error);
87
+ }
88
+ });
89
+ }
90
+ function getSocketAddress() {
91
+ const socketName = `worker-${process.pid}-${threadId}-${Math.round(Math.random() * 1e4)}-${NITRO_DEV_WORKER_ID}.sock`;
92
+ const socketPath = join(NITRO_DEV_WORKER_DIR, socketName);
93
+ switch (process.platform) {
94
+ case "win32": {
95
+ return join(String.raw`\\.\pipe\nitro`, socketPath);
96
+ }
97
+ case "linux": {
98
+ return `\0${socketPath}`;
99
+ }
100
+ default: {
101
+ return socketPath;
102
+ }
103
+ }
104
+ }
105
+ async function shutdown() {
83
106
  server.closeAllConnections?.();
84
107
  await Promise.all([
85
- new Promise((resolve) => listener.close(resolve)),
108
+ new Promise((resolve) => listener?.close(resolve)),
86
109
  nitroApp.hooks.callHook("close").catch(console.error)
87
110
  ]);
88
- }
89
- parentPort?.on("message", async (msg) => {
90
- if (msg && msg.event === "shutdown") {
91
- await onShutdown();
92
- parentPort?.postMessage({ event: "exit" });
93
- }
94
- });
95
- if (import.meta._tasks) {
96
- startScheduleRunner();
111
+ parentPort?.postMessage({ event: "exit" });
97
112
  }
@@ -67,7 +67,7 @@ export async function defaultHandler(error, event, opts) {
67
67
  "content-security-policy": "script-src 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self';"
68
68
  };
69
69
  if (statusCode === 404 || !getResponseHeader(event, "cache-control")) {
70
- headers["Cache-Control"] = "no-cache";
70
+ headers["cache-control"] = "no-cache";
71
71
  }
72
72
  const body = useJSON ? {
73
73
  error: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitropack-nightly",
3
- "version": "2.11.3-20250306-111821.d219707f",
3
+ "version": "2.11.4-20250306-152741.e20071e0",
4
4
  "description": "Build and Deploy Universal JavaScript Servers",
5
5
  "repository": "nitrojs/nitro",
6
6
  "license": "MIT",