srvx 0.5.2 → 0.7.0
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.mjs +13 -0
- package/dist/_plugins.mjs +16 -0
- package/dist/_url.d.mts +13 -0
- package/dist/_url.mjs +151 -0
- package/dist/bun.d.mts +22 -0
- package/dist/bun.mjs +77 -0
- package/dist/cloudflare.d.mts +10 -0
- package/dist/cloudflare.mjs +53 -0
- package/dist/deno.d.mts +22 -0
- package/dist/deno.mjs +86 -0
- package/dist/generic.d.mts +9 -0
- package/dist/generic.mjs +36 -0
- package/dist/node.d.mts +55 -0
- package/dist/node.mjs +813 -0
- package/dist/service-worker.d.mts +10 -0
- package/dist/service-worker.mjs +80 -0
- package/dist/types.d.mts +210 -218
- package/package.json +29 -26
- package/dist/adapters/bun.d.mts +0 -24
- package/dist/adapters/bun.mjs +0 -79
- package/dist/adapters/cloudflare.d.mts +0 -12
- package/dist/adapters/cloudflare.mjs +0 -53
- package/dist/adapters/deno.d.mts +0 -25
- package/dist/adapters/deno.mjs +0 -82
- package/dist/adapters/generic.d.mts +0 -12
- package/dist/adapters/generic.mjs +0 -31
- package/dist/adapters/node.d.mts +0 -50
- package/dist/adapters/node.mjs +0 -977
- package/dist/adapters/service-worker.d.mts +0 -14
- package/dist/adapters/service-worker.mjs +0 -98
- package/dist/shared/srvx.BD9sRkkl.mjs +0 -16
- package/dist/shared/srvx.Ctaz0clH.mjs +0 -172
- package/dist/shared/srvx.DEE2RO4O.d.mts +0 -5
- package/dist/shared/srvx.DhN4g5wJ.mjs +0 -76
package/dist/adapters/bun.d.mts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ServerOptions, Server, BunFetchHandler } from '../types.mjs';
|
|
2
|
-
import * as Bun from 'bun';
|
|
3
|
-
export { F as URL } from '../shared/srvx.DEE2RO4O.mjs';
|
|
4
|
-
import 'node:http';
|
|
5
|
-
import 'node:https';
|
|
6
|
-
import 'node:net';
|
|
7
|
-
import '@cloudflare/workers-types';
|
|
8
|
-
|
|
9
|
-
declare const Response: typeof globalThis.Response;
|
|
10
|
-
declare function serve(options: ServerOptions): BunServer;
|
|
11
|
-
declare class BunServer implements Server<BunFetchHandler> {
|
|
12
|
-
readonly runtime = "bun";
|
|
13
|
-
readonly options: ServerOptions;
|
|
14
|
-
readonly bun: Server["bun"];
|
|
15
|
-
readonly serveOptions: Bun.ServeOptions | Bun.TLSServeOptions;
|
|
16
|
-
readonly fetch: BunFetchHandler;
|
|
17
|
-
constructor(options: ServerOptions);
|
|
18
|
-
serve(): Promise<this>;
|
|
19
|
-
get url(): string | undefined;
|
|
20
|
-
ready(): Promise<this>;
|
|
21
|
-
close(closeAll?: boolean): Promise<void>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { Response, serve };
|
package/dist/adapters/bun.mjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { r as resolveTLSOptions, a as resolvePortAndHost, p as printListening, f as fmtURL } from '../shared/srvx.Ctaz0clH.mjs';
|
|
2
|
-
export { F as URL } from '../shared/srvx.Ctaz0clH.mjs';
|
|
3
|
-
import { w as wrapFetch } from '../shared/srvx.DhN4g5wJ.mjs';
|
|
4
|
-
import 'node:fs';
|
|
5
|
-
|
|
6
|
-
const Response = globalThis.Response;
|
|
7
|
-
function serve(options) {
|
|
8
|
-
return new BunServer(options);
|
|
9
|
-
}
|
|
10
|
-
class BunServer {
|
|
11
|
-
constructor(options) {
|
|
12
|
-
this.runtime = "bun";
|
|
13
|
-
this.bun = {};
|
|
14
|
-
this.options = options;
|
|
15
|
-
const fetchHandler = wrapFetch(this, this.options.fetch);
|
|
16
|
-
this.fetch = (request, server) => {
|
|
17
|
-
Object.defineProperties(request, {
|
|
18
|
-
runtime: {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
value: { runtime: "bun", bun: { server } }
|
|
21
|
-
},
|
|
22
|
-
ip: {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get() {
|
|
25
|
-
return server?.requestIP(request)?.address;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return fetchHandler(request);
|
|
30
|
-
};
|
|
31
|
-
const tls = resolveTLSOptions(this.options);
|
|
32
|
-
this.serveOptions = {
|
|
33
|
-
...resolvePortAndHost(this.options),
|
|
34
|
-
reusePort: this.options.reusePort,
|
|
35
|
-
error: this.options.onError,
|
|
36
|
-
...this.options.bun,
|
|
37
|
-
tls: {
|
|
38
|
-
cert: tls?.cert,
|
|
39
|
-
key: tls?.key,
|
|
40
|
-
passphrase: tls?.passphrase,
|
|
41
|
-
...this.options.bun?.tls
|
|
42
|
-
},
|
|
43
|
-
fetch: this.fetch
|
|
44
|
-
};
|
|
45
|
-
if (!options.manual) {
|
|
46
|
-
this.serve();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
serve() {
|
|
50
|
-
if (!this.bun.server) {
|
|
51
|
-
this.bun.server = Bun.serve(this.serveOptions);
|
|
52
|
-
}
|
|
53
|
-
printListening(this.options, this.url);
|
|
54
|
-
return Promise.resolve(this);
|
|
55
|
-
}
|
|
56
|
-
get url() {
|
|
57
|
-
const server = this.bun?.server;
|
|
58
|
-
if (!server) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const address = server.address;
|
|
62
|
-
if (address) {
|
|
63
|
-
return fmtURL(
|
|
64
|
-
address.address,
|
|
65
|
-
address.port,
|
|
66
|
-
server.protocol === "https"
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
return server.url.href;
|
|
70
|
-
}
|
|
71
|
-
ready() {
|
|
72
|
-
return Promise.resolve(this);
|
|
73
|
-
}
|
|
74
|
-
close(closeAll) {
|
|
75
|
-
return Promise.resolve(this.bun?.server?.stop(closeAll));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export { Response, serve };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ServerOptions, Server } from '../types.mjs';
|
|
2
|
-
import * as CF from '@cloudflare/workers-types';
|
|
3
|
-
import 'node:http';
|
|
4
|
-
import 'node:https';
|
|
5
|
-
import 'node:net';
|
|
6
|
-
import 'bun';
|
|
7
|
-
|
|
8
|
-
declare const URL: typeof globalThis.URL;
|
|
9
|
-
declare const Response: typeof globalThis.Response;
|
|
10
|
-
declare function serve(options: ServerOptions): Server<CF.ExportedHandlerFetchHandler>;
|
|
11
|
-
|
|
12
|
-
export { Response, URL, serve };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { w as wrapFetch } from '../shared/srvx.DhN4g5wJ.mjs';
|
|
2
|
-
import { w as wrapFetchOnError } from '../shared/srvx.BD9sRkkl.mjs';
|
|
3
|
-
|
|
4
|
-
const URL = globalThis.URL;
|
|
5
|
-
const Response = globalThis.Response;
|
|
6
|
-
function serve(options) {
|
|
7
|
-
return new CloudflareServer(options);
|
|
8
|
-
}
|
|
9
|
-
class CloudflareServer {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.runtime = "cloudflare";
|
|
12
|
-
this.options = options;
|
|
13
|
-
const fetchHandler = wrapFetch(
|
|
14
|
-
this,
|
|
15
|
-
wrapFetchOnError(this.options.fetch, this.options.onError)
|
|
16
|
-
);
|
|
17
|
-
this.fetch = (request, env, context) => {
|
|
18
|
-
Object.defineProperties(request, {
|
|
19
|
-
runtime: {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
value: { runtime: "cloudflare", cloudflare: { env, context } }
|
|
22
|
-
}
|
|
23
|
-
// TODO
|
|
24
|
-
// ip: {
|
|
25
|
-
// enumerable: true,
|
|
26
|
-
// get() {
|
|
27
|
-
// return;
|
|
28
|
-
// },
|
|
29
|
-
// },
|
|
30
|
-
});
|
|
31
|
-
return fetchHandler(request);
|
|
32
|
-
};
|
|
33
|
-
this.serveOptions = {
|
|
34
|
-
fetch: this.fetch
|
|
35
|
-
};
|
|
36
|
-
if (!options.manual) {
|
|
37
|
-
this.serve();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
serve() {
|
|
41
|
-
addEventListener("fetch", (event) => {
|
|
42
|
-
event.respondWith(this.fetch(event.request, {}, event));
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
ready() {
|
|
46
|
-
return Promise.resolve().then(() => this);
|
|
47
|
-
}
|
|
48
|
-
close() {
|
|
49
|
-
return Promise.resolve();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export { Response, URL, serve };
|
package/dist/adapters/deno.d.mts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ServerOptions, Server, DenoFetchHandler } from '../types.mjs';
|
|
2
|
-
export { F as URL } from '../shared/srvx.DEE2RO4O.mjs';
|
|
3
|
-
import 'node:http';
|
|
4
|
-
import 'node:https';
|
|
5
|
-
import 'node:net';
|
|
6
|
-
import 'bun';
|
|
7
|
-
import '@cloudflare/workers-types';
|
|
8
|
-
|
|
9
|
-
declare const Response: typeof globalThis.Response;
|
|
10
|
-
declare function serve(options: ServerOptions): DenoServer;
|
|
11
|
-
declare class DenoServer implements Server<DenoFetchHandler> {
|
|
12
|
-
#private;
|
|
13
|
-
readonly runtime = "deno";
|
|
14
|
-
readonly options: ServerOptions;
|
|
15
|
-
readonly deno: Server["deno"];
|
|
16
|
-
readonly serveOptions: Deno.ServeTcpOptions | (Deno.ServeTcpOptions & Deno.TlsCertifiedKeyPem);
|
|
17
|
-
readonly fetch: DenoFetchHandler;
|
|
18
|
-
constructor(options: ServerOptions);
|
|
19
|
-
serve(): Promise<this>;
|
|
20
|
-
get url(): string | undefined;
|
|
21
|
-
ready(): Promise<Server>;
|
|
22
|
-
close(): Promise<void | undefined>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { Response, serve };
|
package/dist/adapters/deno.mjs
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { r as resolveTLSOptions, a as resolvePortAndHost, p as printListening, f as fmtURL } from '../shared/srvx.Ctaz0clH.mjs';
|
|
2
|
-
export { F as URL } from '../shared/srvx.Ctaz0clH.mjs';
|
|
3
|
-
import { w as wrapFetch } from '../shared/srvx.DhN4g5wJ.mjs';
|
|
4
|
-
import 'node:fs';
|
|
5
|
-
|
|
6
|
-
const Response = globalThis.Response;
|
|
7
|
-
function serve(options) {
|
|
8
|
-
return new DenoServer(options);
|
|
9
|
-
}
|
|
10
|
-
class DenoServer {
|
|
11
|
-
constructor(options) {
|
|
12
|
-
this.runtime = "deno";
|
|
13
|
-
this.deno = {};
|
|
14
|
-
this.options = options;
|
|
15
|
-
const fetchHandler = wrapFetch(this, this.options.fetch);
|
|
16
|
-
this.fetch = (request, info) => {
|
|
17
|
-
Object.defineProperties(request, {
|
|
18
|
-
runtime: {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
value: { runtime: "deno", deno: { info, server: this.deno?.server } }
|
|
21
|
-
},
|
|
22
|
-
ip: {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get() {
|
|
25
|
-
return info?.remoteAddr?.hostname;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return fetchHandler(request);
|
|
30
|
-
};
|
|
31
|
-
const tls = resolveTLSOptions(this.options);
|
|
32
|
-
this.serveOptions = {
|
|
33
|
-
...resolvePortAndHost(this.options),
|
|
34
|
-
reusePort: this.options.reusePort,
|
|
35
|
-
onError: this.options.onError,
|
|
36
|
-
...tls ? { key: tls.key, cert: tls.cert, passphrase: tls.passphrase } : {},
|
|
37
|
-
...this.options.deno
|
|
38
|
-
};
|
|
39
|
-
if (!options.manual) {
|
|
40
|
-
this.serve();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
#listeningPromise;
|
|
44
|
-
#listeningInfo;
|
|
45
|
-
serve() {
|
|
46
|
-
if (this.deno?.server) {
|
|
47
|
-
return Promise.resolve(this.#listeningPromise).then(() => this);
|
|
48
|
-
}
|
|
49
|
-
const onListenPromise = Promise.withResolvers();
|
|
50
|
-
this.#listeningPromise = onListenPromise.promise;
|
|
51
|
-
this.deno.server = Deno.serve(
|
|
52
|
-
{
|
|
53
|
-
...this.serveOptions,
|
|
54
|
-
onListen: (info) => {
|
|
55
|
-
this.#listeningInfo = info;
|
|
56
|
-
if (this.options.deno?.onListen) {
|
|
57
|
-
this.options.deno.onListen(info);
|
|
58
|
-
}
|
|
59
|
-
printListening(this.options, this.url);
|
|
60
|
-
onListenPromise.resolve();
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
this.fetch
|
|
64
|
-
);
|
|
65
|
-
return Promise.resolve(this.#listeningPromise).then(() => this);
|
|
66
|
-
}
|
|
67
|
-
get url() {
|
|
68
|
-
return this.#listeningInfo ? fmtURL(
|
|
69
|
-
this.#listeningInfo.hostname,
|
|
70
|
-
this.#listeningInfo.port,
|
|
71
|
-
!!this.serveOptions.cert
|
|
72
|
-
) : void 0;
|
|
73
|
-
}
|
|
74
|
-
ready() {
|
|
75
|
-
return Promise.resolve(this.#listeningPromise).then(() => this);
|
|
76
|
-
}
|
|
77
|
-
close() {
|
|
78
|
-
return Promise.resolve(this.deno?.server?.shutdown());
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export { Response, serve };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ServerOptions, Server } from '../types.mjs';
|
|
2
|
-
import 'node:http';
|
|
3
|
-
import 'node:https';
|
|
4
|
-
import 'node:net';
|
|
5
|
-
import 'bun';
|
|
6
|
-
import '@cloudflare/workers-types';
|
|
7
|
-
|
|
8
|
-
declare const URL: typeof globalThis.URL;
|
|
9
|
-
declare const Response: typeof globalThis.Response;
|
|
10
|
-
declare function serve(options: ServerOptions): Server;
|
|
11
|
-
|
|
12
|
-
export { Response, URL, serve };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { w as wrapFetch } from '../shared/srvx.DhN4g5wJ.mjs';
|
|
2
|
-
import { w as wrapFetchOnError } from '../shared/srvx.BD9sRkkl.mjs';
|
|
3
|
-
|
|
4
|
-
const URL = globalThis.URL;
|
|
5
|
-
const Response = globalThis.Response;
|
|
6
|
-
function serve(options) {
|
|
7
|
-
return new GenericServer(options);
|
|
8
|
-
}
|
|
9
|
-
class GenericServer {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.runtime = "generic";
|
|
12
|
-
this.options = options;
|
|
13
|
-
const fetchHandler = wrapFetch(
|
|
14
|
-
this,
|
|
15
|
-
wrapFetchOnError(this.options.fetch, this.options.onError)
|
|
16
|
-
);
|
|
17
|
-
this.fetch = (request) => {
|
|
18
|
-
return Promise.resolve(fetchHandler(request));
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
serve() {
|
|
22
|
-
}
|
|
23
|
-
ready() {
|
|
24
|
-
return Promise.resolve(this);
|
|
25
|
-
}
|
|
26
|
-
close() {
|
|
27
|
-
return Promise.resolve();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { Response, URL, serve };
|
package/dist/adapters/node.d.mts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ServerRequest, ServerOptions, Server, FetchHandler, NodeHttpHandler } from '../types.mjs';
|
|
2
|
-
export { F as URL } from '../shared/srvx.DEE2RO4O.mjs';
|
|
3
|
-
import NodeHttp__default from 'node:http';
|
|
4
|
-
import { Readable } from 'node:stream';
|
|
5
|
-
import 'node:https';
|
|
6
|
-
import 'node:net';
|
|
7
|
-
import 'bun';
|
|
8
|
-
import '@cloudflare/workers-types';
|
|
9
|
-
|
|
10
|
-
type NodeResponse = InstanceType<typeof NodeResponse>;
|
|
11
|
-
/**
|
|
12
|
-
* Fast Response for Node.js runtime
|
|
13
|
-
*
|
|
14
|
-
* It is faster because in most cases it doesn't create a full Response instance.
|
|
15
|
-
*/
|
|
16
|
-
declare const NodeResponse: {
|
|
17
|
-
new (body?: BodyInit | null, init?: ResponseInit): globalThis.Response & {
|
|
18
|
-
readonly nodeResponse: () => {
|
|
19
|
-
status: number;
|
|
20
|
-
statusText: string;
|
|
21
|
-
headers: NodeHttp__default.OutgoingHttpHeader[];
|
|
22
|
-
body: string | Buffer | Uint8Array | DataView | ReadableStream<Uint8Array> | Readable | undefined | null;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
declare const NodeRequest: {
|
|
28
|
-
new (nodeCtx: {
|
|
29
|
-
req: NodeHttp__default.IncomingMessage;
|
|
30
|
-
res: NodeHttp__default.ServerResponse;
|
|
31
|
-
}): ServerRequest;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
declare const NodeRequestHeaders: {
|
|
35
|
-
new (nodeCtx: {
|
|
36
|
-
req: NodeHttp__default.IncomingMessage;
|
|
37
|
-
res?: NodeHttp__default.ServerResponse;
|
|
38
|
-
}): globalThis.Headers;
|
|
39
|
-
};
|
|
40
|
-
declare const NodeResponseHeaders: {
|
|
41
|
-
new (nodeCtx: {
|
|
42
|
-
req?: NodeHttp__default.IncomingMessage;
|
|
43
|
-
res: NodeHttp__default.ServerResponse;
|
|
44
|
-
}): globalThis.Headers;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
declare function serve(options: ServerOptions): Server;
|
|
48
|
-
declare function toNodeHandler(fetchHandler: FetchHandler): NodeHttpHandler;
|
|
49
|
-
|
|
50
|
-
export { NodeRequest, NodeRequestHeaders, NodeResponse, NodeResponseHeaders, NodeRequest as Request, NodeResponse as Response, serve, toNodeHandler };
|