@@ -13,3 +13,3 @@ import { BunFetchHandler, Server, ServerOptions } from "../types.mjs"; | ||
| readonly bun: Server["bun"]; | ||
| readonly serveOptions: bun.Serve.Options<any>; | ||
| readonly serveOptions: bun.Serve.Options<any> | undefined; | ||
| readonly fetch: BunFetchHandler; | ||
@@ -16,0 +16,0 @@ constructor(options: ServerOptions); |
@@ -23,6 +23,12 @@ import { t as FastURL } from "../_chunks/_url.mjs"; | ||
| const fetchHandler = wrapFetch(this); | ||
| const loader = globalThis.__srvxLoader__; | ||
| if (loader) { | ||
| this.fetch = fetchHandler; | ||
| loader(fetchHandler); | ||
| return; | ||
| } | ||
| this.#wait = createWaitUntil(); | ||
| this.fetch = (request, server) => { | ||
| Object.defineProperties(request, { | ||
| waitUntil: { value: this.#wait.waitUntil }, | ||
| waitUntil: { value: this.#wait?.waitUntil }, | ||
| runtime: { | ||
@@ -76,5 +82,5 @@ enumerable: true, | ||
| async close(closeAll) { | ||
| await Promise.all([this.#wait.wait(), Promise.resolve(this.bun?.server?.stop(closeAll))]); | ||
| await Promise.all([this.#wait?.wait(), Promise.resolve(this.bun?.server?.stop(closeAll))]); | ||
| } | ||
| }; | ||
| export { FastResponse, FastURL, serve }; |
@@ -12,3 +12,3 @@ import { DenoFetchHandler, Server, ServerOptions } from "../types.mjs"; | ||
| readonly deno: Server["deno"]; | ||
| readonly serveOptions: Deno.ServeTcpOptions | (Deno.ServeTcpOptions & Deno.TlsCertifiedKeyPem); | ||
| readonly serveOptions: Deno.ServeTcpOptions | (Deno.ServeTcpOptions & Deno.TlsCertifiedKeyPem) | undefined; | ||
| readonly fetch: DenoFetchHandler; | ||
@@ -15,0 +15,0 @@ constructor(options: ServerOptions); |
@@ -25,6 +25,12 @@ import { t as FastURL } from "../_chunks/_url.mjs"; | ||
| const fetchHandler = wrapFetch(this); | ||
| const loader = globalThis.__srvxLoader__; | ||
| if (loader) { | ||
| this.fetch = fetchHandler; | ||
| loader(fetchHandler); | ||
| return; | ||
| } | ||
| this.#wait = createWaitUntil(); | ||
| this.fetch = (request, info) => { | ||
| Object.defineProperties(request, { | ||
| waitUntil: { value: this.#wait.waitUntil }, | ||
| waitUntil: { value: this.#wait?.waitUntil }, | ||
| runtime: { | ||
@@ -85,5 +91,5 @@ enumerable: true, | ||
| async close() { | ||
| await Promise.all([this.#wait.wait(), Promise.resolve(this.deno?.server?.shutdown())]); | ||
| await Promise.all([this.#wait?.wait(), Promise.resolve(this.deno?.server?.shutdown())]); | ||
| } | ||
| }; | ||
| export { FastResponse, FastURL, serve }; |
@@ -673,4 +673,9 @@ import { n as lazyInherit, t as FastURL } from "../_chunks/_url.mjs"; | ||
| errorPlugin(this); | ||
| const fetchHandler = this.fetch = wrapFetch(this); | ||
| const loader = globalThis.__srvxLoader__; | ||
| if (loader) { | ||
| loader(fetchHandler); | ||
| return; | ||
| } | ||
| gracefulShutdownPlugin(this); | ||
| const fetchHandler = this.fetch = wrapFetch(this); | ||
| this.#wait = createWaitUntil(); | ||
@@ -682,3 +687,3 @@ const handler = (nodeReq, nodeRes) => { | ||
| }); | ||
| request.waitUntil = this.#wait.waitUntil; | ||
| request.waitUntil = this.#wait?.waitUntil; | ||
| const res = fetchHandler(request); | ||
@@ -733,3 +738,3 @@ return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponse(nodeRes, resolvedRes)) : sendNodeResponse(nodeRes, res); | ||
| async close(closeAll) { | ||
| await Promise.all([this.#wait.wait(), new Promise((resolve, reject) => { | ||
| await Promise.all([this.#wait?.wait(), new Promise((resolve, reject) => { | ||
| const server = this.node?.server; | ||
@@ -736,0 +741,0 @@ if (server && closeAll && "closeAllConnections" in server) server.closeAllConnections(); |
+13
-5
@@ -37,3 +37,4 @@ import { pathToFileURL } from "node:url"; | ||
| let mod; | ||
| let listenHandler; | ||
| let interceptedNodeHandler; | ||
| let interceptedFetchHandler; | ||
| try { | ||
@@ -43,3 +44,4 @@ if (opts.interceptHttpListen !== false) { | ||
| mod = loaded.res; | ||
| listenHandler = loaded.listenHandler; | ||
| interceptedNodeHandler = loaded.listenHandler; | ||
| interceptedFetchHandler = loaded.fetchHandler; | ||
| } else mod = await import(url); | ||
@@ -55,7 +57,7 @@ } catch (error) { | ||
| mod = await opts?.onLoad?.(mod) || mod; | ||
| let fetchHandler = mod?.fetch || mod?.default?.fetch || mod?.default?.default?.fetch; | ||
| let fetchHandler = mod?.fetch || mod?.default?.fetch || mod?.default?.default?.fetch || interceptedFetchHandler; | ||
| if (!fetchHandler && typeof mod?.default === "function" && mod.default.length < 2) fetchHandler = mod.default; | ||
| let nodeCompat = false; | ||
| if (!fetchHandler && opts.nodeCompat !== false) { | ||
| const nodeHandler = listenHandler || (typeof mod?.default === "function" ? mod.default : void 0); | ||
| const nodeHandler = interceptedNodeHandler || (typeof mod?.default === "function" ? mod.default : void 0); | ||
| if (nodeHandler) { | ||
@@ -80,2 +82,6 @@ nodeCompat = true; | ||
| let listenHandler; | ||
| let fetchHandler; | ||
| globalThis.__srvxLoader__ = (handler) => { | ||
| fetchHandler = handler; | ||
| }; | ||
| try { | ||
@@ -103,6 +109,8 @@ nodeHTTP$1.Server.prototype.listen = function(arg1, arg2) { | ||
| nodeHTTP$1.Server.prototype.listen = originalListen; | ||
| delete globalThis.__srvxLoader__; | ||
| } | ||
| return { | ||
| res, | ||
| listenHandler | ||
| listenHandler, | ||
| fetchHandler | ||
| }; | ||
@@ -109,0 +117,0 @@ }); |
+1
-1
| { | ||
| "name": "srvx", | ||
| "version": "0.11.3", | ||
| "version": "0.11.4", | ||
| "description": "Universal Server.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://srvx.h3.dev", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
107063
0.63%2308
1.1%80
2.56%