@mokup/server 1.0.1 → 1.0.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/index.cjs +17 -3
- package/dist/index.d.cts +21 -22
- package/dist/index.d.mts +21 -22
- package/dist/index.d.ts +21 -22
- package/dist/index.mjs +17 -3
- package/dist/shared/{server.C0FGI34s.d.cts → server.DNITwCtQ.d.cts} +4 -4
- package/dist/shared/{server.C0FGI34s.d.mts → server.DNITwCtQ.d.mts} +4 -4
- package/dist/shared/{server.C0FGI34s.d.ts → server.DNITwCtQ.d.ts} +4 -4
- package/dist/worker.d.cts +4 -4
- package/dist/worker.d.mts +4 -4
- package/dist/worker.d.ts +4 -4
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -189,6 +189,18 @@ function applyRouteOverrides(response, route) {
|
|
|
189
189
|
}
|
|
190
190
|
return new Response(response.body, { status, headers });
|
|
191
191
|
}
|
|
192
|
+
function resolveResponse(value, fallback) {
|
|
193
|
+
if (value instanceof Response) {
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
if (value && typeof value === "object" && "res" in value) {
|
|
197
|
+
const resolved = value.res;
|
|
198
|
+
if (resolved instanceof Response) {
|
|
199
|
+
return resolved;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return fallback;
|
|
203
|
+
}
|
|
192
204
|
function normalizeHandlerValue(c, value) {
|
|
193
205
|
if (value instanceof Response) {
|
|
194
206
|
return value;
|
|
@@ -224,17 +236,19 @@ function createRouteHandler(route) {
|
|
|
224
236
|
function createFinalizeMiddleware(route) {
|
|
225
237
|
return async (c, next) => {
|
|
226
238
|
const response = await next();
|
|
227
|
-
const resolved = response
|
|
239
|
+
const resolved = resolveResponse(response, c.res);
|
|
228
240
|
if (route.delay && route.delay > 0) {
|
|
229
241
|
await delay(route.delay);
|
|
230
242
|
}
|
|
231
|
-
|
|
243
|
+
const overridden = applyRouteOverrides(resolved, route);
|
|
244
|
+
c.res = overridden;
|
|
245
|
+
return overridden;
|
|
232
246
|
};
|
|
233
247
|
}
|
|
234
248
|
function wrapMiddleware(handler) {
|
|
235
249
|
return async (c, next) => {
|
|
236
250
|
const response = await handler(c, next);
|
|
237
|
-
return response
|
|
251
|
+
return resolveResponse(response, c.res);
|
|
238
252
|
};
|
|
239
253
|
}
|
|
240
254
|
function createHonoApp(routes) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { S as ServerOptions, F as FetchHandler, W as WorkerInput } from './shared/server.DNITwCtQ.cjs';
|
|
2
|
+
export { a as WorkerBundle } from './shared/server.DNITwCtQ.cjs';
|
|
3
3
|
import { RouteToken } from '@mokup/runtime';
|
|
4
4
|
export { Manifest, ManifestRoute, ModuleMap, RuntimeOptions } from '@mokup/runtime';
|
|
5
5
|
import { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
@@ -21,9 +21,9 @@ interface NodeResponseLike {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
type NextFunction = (error?: unknown) => void;
|
|
24
|
-
declare function createConnectMiddleware(options:
|
|
24
|
+
declare function createConnectMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: NextFunction) => Promise<void>;
|
|
25
25
|
|
|
26
|
-
declare function createExpressMiddleware(options:
|
|
26
|
+
declare function createExpressMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: (error?: unknown) => void) => Promise<void>;
|
|
27
27
|
|
|
28
28
|
interface FastifyRequestLike extends NodeRequestLike {
|
|
29
29
|
raw?: NodeRequestLike;
|
|
@@ -36,16 +36,15 @@ interface FastifyReplyLike {
|
|
|
36
36
|
interface FastifyInstanceLike {
|
|
37
37
|
addHook: (name: 'onRequest' | 'preHandler', handler: (request: FastifyRequestLike, reply: FastifyReplyLike) => Promise<void> | void) => void;
|
|
38
38
|
}
|
|
39
|
-
declare function createFastifyPlugin(options:
|
|
39
|
+
declare function createFastifyPlugin(options: ServerOptions): (instance: FastifyInstanceLike) => Promise<void>;
|
|
40
40
|
|
|
41
|
-
declare function createFetchHandler(options:
|
|
41
|
+
declare function createFetchHandler(options: ServerOptions): FetchHandler;
|
|
42
42
|
|
|
43
43
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
44
|
-
type
|
|
45
|
-
type
|
|
46
|
-
type MockResponse = unknown | MockResponseHandler;
|
|
44
|
+
type RequestHandler = (context: Context) => Response | Promise<Response> | unknown;
|
|
45
|
+
type RouteResponse = unknown | RequestHandler;
|
|
47
46
|
interface ResolvedMiddleware {
|
|
48
|
-
handle:
|
|
47
|
+
handle: MiddlewareHandler;
|
|
49
48
|
source: string;
|
|
50
49
|
index: number;
|
|
51
50
|
}
|
|
@@ -55,7 +54,7 @@ interface ResolvedRoute {
|
|
|
55
54
|
method: HttpMethod;
|
|
56
55
|
tokens: RouteToken[];
|
|
57
56
|
score: number[];
|
|
58
|
-
handler:
|
|
57
|
+
handler: RouteResponse;
|
|
59
58
|
middlewares?: ResolvedMiddleware[];
|
|
60
59
|
status?: number;
|
|
61
60
|
headers?: Record<string, string>;
|
|
@@ -66,7 +65,7 @@ type RouteTable = ResolvedRoute[];
|
|
|
66
65
|
|
|
67
66
|
type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
|
|
68
67
|
|
|
69
|
-
interface
|
|
68
|
+
interface FetchServerOptions {
|
|
70
69
|
dir?: DirInput;
|
|
71
70
|
prefix?: string;
|
|
72
71
|
include?: RegExp | RegExp[];
|
|
@@ -81,15 +80,15 @@ interface MokupFetchServerOptions {
|
|
|
81
80
|
port?: number;
|
|
82
81
|
root?: string;
|
|
83
82
|
}
|
|
84
|
-
type
|
|
83
|
+
type FetchServerOptionsInput = FetchServerOptions | FetchServerOptions[];
|
|
85
84
|
|
|
86
|
-
interface
|
|
85
|
+
interface FetchServer {
|
|
87
86
|
fetch: (request: Request) => Promise<Response>;
|
|
88
87
|
refresh: () => Promise<void>;
|
|
89
88
|
getRoutes: () => RouteTable;
|
|
90
89
|
close?: () => Promise<void>;
|
|
91
90
|
}
|
|
92
|
-
declare function createFetchServer(options?:
|
|
91
|
+
declare function createFetchServer(options?: FetchServerOptionsInput): Promise<FetchServer>;
|
|
93
92
|
|
|
94
93
|
interface HonoContextLike {
|
|
95
94
|
req: {
|
|
@@ -104,7 +103,7 @@ interface HonoRouteLike {
|
|
|
104
103
|
method: string;
|
|
105
104
|
handler: HonoMiddleware;
|
|
106
105
|
}
|
|
107
|
-
declare function createHonoMiddleware(options:
|
|
106
|
+
declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
|
|
108
107
|
routes: HonoRouteLike[];
|
|
109
108
|
};
|
|
110
109
|
|
|
@@ -119,13 +118,13 @@ interface KoaContextLike {
|
|
|
119
118
|
set: (header: Record<string, string>) => void;
|
|
120
119
|
}
|
|
121
120
|
type KoaNext = () => Promise<unknown>;
|
|
122
|
-
declare function createKoaMiddleware(options:
|
|
121
|
+
declare function createKoaMiddleware(options: ServerOptions): (ctx: KoaContextLike, next: KoaNext) => Promise<void>;
|
|
123
122
|
|
|
124
|
-
interface
|
|
123
|
+
interface FetchWorker {
|
|
125
124
|
fetch: (request: Request) => Promise<Response>;
|
|
126
125
|
}
|
|
127
|
-
declare function createMokupWorker(input: string): Promise<
|
|
128
|
-
declare function createMokupWorker(input: Exclude<
|
|
126
|
+
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
127
|
+
declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
|
|
129
128
|
|
|
130
|
-
export { FetchHandler,
|
|
131
|
-
export type {
|
|
129
|
+
export { FetchHandler, ServerOptions, WorkerInput, createConnectMiddleware, createExpressMiddleware, createFastifyPlugin, createFetchHandler, createFetchServer, createHonoMiddleware, createKoaMiddleware, createMokupWorker };
|
|
130
|
+
export type { FetchServer, FetchServerOptions, FetchServerOptionsInput };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { S as ServerOptions, F as FetchHandler, W as WorkerInput } from './shared/server.DNITwCtQ.mjs';
|
|
2
|
+
export { a as WorkerBundle } from './shared/server.DNITwCtQ.mjs';
|
|
3
3
|
import { RouteToken } from '@mokup/runtime';
|
|
4
4
|
export { Manifest, ManifestRoute, ModuleMap, RuntimeOptions } from '@mokup/runtime';
|
|
5
5
|
import { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
@@ -21,9 +21,9 @@ interface NodeResponseLike {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
type NextFunction = (error?: unknown) => void;
|
|
24
|
-
declare function createConnectMiddleware(options:
|
|
24
|
+
declare function createConnectMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: NextFunction) => Promise<void>;
|
|
25
25
|
|
|
26
|
-
declare function createExpressMiddleware(options:
|
|
26
|
+
declare function createExpressMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: (error?: unknown) => void) => Promise<void>;
|
|
27
27
|
|
|
28
28
|
interface FastifyRequestLike extends NodeRequestLike {
|
|
29
29
|
raw?: NodeRequestLike;
|
|
@@ -36,16 +36,15 @@ interface FastifyReplyLike {
|
|
|
36
36
|
interface FastifyInstanceLike {
|
|
37
37
|
addHook: (name: 'onRequest' | 'preHandler', handler: (request: FastifyRequestLike, reply: FastifyReplyLike) => Promise<void> | void) => void;
|
|
38
38
|
}
|
|
39
|
-
declare function createFastifyPlugin(options:
|
|
39
|
+
declare function createFastifyPlugin(options: ServerOptions): (instance: FastifyInstanceLike) => Promise<void>;
|
|
40
40
|
|
|
41
|
-
declare function createFetchHandler(options:
|
|
41
|
+
declare function createFetchHandler(options: ServerOptions): FetchHandler;
|
|
42
42
|
|
|
43
43
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
44
|
-
type
|
|
45
|
-
type
|
|
46
|
-
type MockResponse = unknown | MockResponseHandler;
|
|
44
|
+
type RequestHandler = (context: Context) => Response | Promise<Response> | unknown;
|
|
45
|
+
type RouteResponse = unknown | RequestHandler;
|
|
47
46
|
interface ResolvedMiddleware {
|
|
48
|
-
handle:
|
|
47
|
+
handle: MiddlewareHandler;
|
|
49
48
|
source: string;
|
|
50
49
|
index: number;
|
|
51
50
|
}
|
|
@@ -55,7 +54,7 @@ interface ResolvedRoute {
|
|
|
55
54
|
method: HttpMethod;
|
|
56
55
|
tokens: RouteToken[];
|
|
57
56
|
score: number[];
|
|
58
|
-
handler:
|
|
57
|
+
handler: RouteResponse;
|
|
59
58
|
middlewares?: ResolvedMiddleware[];
|
|
60
59
|
status?: number;
|
|
61
60
|
headers?: Record<string, string>;
|
|
@@ -66,7 +65,7 @@ type RouteTable = ResolvedRoute[];
|
|
|
66
65
|
|
|
67
66
|
type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
|
|
68
67
|
|
|
69
|
-
interface
|
|
68
|
+
interface FetchServerOptions {
|
|
70
69
|
dir?: DirInput;
|
|
71
70
|
prefix?: string;
|
|
72
71
|
include?: RegExp | RegExp[];
|
|
@@ -81,15 +80,15 @@ interface MokupFetchServerOptions {
|
|
|
81
80
|
port?: number;
|
|
82
81
|
root?: string;
|
|
83
82
|
}
|
|
84
|
-
type
|
|
83
|
+
type FetchServerOptionsInput = FetchServerOptions | FetchServerOptions[];
|
|
85
84
|
|
|
86
|
-
interface
|
|
85
|
+
interface FetchServer {
|
|
87
86
|
fetch: (request: Request) => Promise<Response>;
|
|
88
87
|
refresh: () => Promise<void>;
|
|
89
88
|
getRoutes: () => RouteTable;
|
|
90
89
|
close?: () => Promise<void>;
|
|
91
90
|
}
|
|
92
|
-
declare function createFetchServer(options?:
|
|
91
|
+
declare function createFetchServer(options?: FetchServerOptionsInput): Promise<FetchServer>;
|
|
93
92
|
|
|
94
93
|
interface HonoContextLike {
|
|
95
94
|
req: {
|
|
@@ -104,7 +103,7 @@ interface HonoRouteLike {
|
|
|
104
103
|
method: string;
|
|
105
104
|
handler: HonoMiddleware;
|
|
106
105
|
}
|
|
107
|
-
declare function createHonoMiddleware(options:
|
|
106
|
+
declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
|
|
108
107
|
routes: HonoRouteLike[];
|
|
109
108
|
};
|
|
110
109
|
|
|
@@ -119,13 +118,13 @@ interface KoaContextLike {
|
|
|
119
118
|
set: (header: Record<string, string>) => void;
|
|
120
119
|
}
|
|
121
120
|
type KoaNext = () => Promise<unknown>;
|
|
122
|
-
declare function createKoaMiddleware(options:
|
|
121
|
+
declare function createKoaMiddleware(options: ServerOptions): (ctx: KoaContextLike, next: KoaNext) => Promise<void>;
|
|
123
122
|
|
|
124
|
-
interface
|
|
123
|
+
interface FetchWorker {
|
|
125
124
|
fetch: (request: Request) => Promise<Response>;
|
|
126
125
|
}
|
|
127
|
-
declare function createMokupWorker(input: string): Promise<
|
|
128
|
-
declare function createMokupWorker(input: Exclude<
|
|
126
|
+
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
127
|
+
declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
|
|
129
128
|
|
|
130
|
-
export { FetchHandler,
|
|
131
|
-
export type {
|
|
129
|
+
export { FetchHandler, ServerOptions, WorkerInput, createConnectMiddleware, createExpressMiddleware, createFastifyPlugin, createFetchHandler, createFetchServer, createHonoMiddleware, createKoaMiddleware, createMokupWorker };
|
|
130
|
+
export type { FetchServer, FetchServerOptions, FetchServerOptionsInput };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { S as ServerOptions, F as FetchHandler, W as WorkerInput } from './shared/server.DNITwCtQ.js';
|
|
2
|
+
export { a as WorkerBundle } from './shared/server.DNITwCtQ.js';
|
|
3
3
|
import { RouteToken } from '@mokup/runtime';
|
|
4
4
|
export { Manifest, ManifestRoute, ModuleMap, RuntimeOptions } from '@mokup/runtime';
|
|
5
5
|
import { Context, MiddlewareHandler } from '@mokup/shared/hono';
|
|
@@ -21,9 +21,9 @@ interface NodeResponseLike {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
type NextFunction = (error?: unknown) => void;
|
|
24
|
-
declare function createConnectMiddleware(options:
|
|
24
|
+
declare function createConnectMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: NextFunction) => Promise<void>;
|
|
25
25
|
|
|
26
|
-
declare function createExpressMiddleware(options:
|
|
26
|
+
declare function createExpressMiddleware(options: ServerOptions): (req: NodeRequestLike, res: NodeResponseLike, next: (error?: unknown) => void) => Promise<void>;
|
|
27
27
|
|
|
28
28
|
interface FastifyRequestLike extends NodeRequestLike {
|
|
29
29
|
raw?: NodeRequestLike;
|
|
@@ -36,16 +36,15 @@ interface FastifyReplyLike {
|
|
|
36
36
|
interface FastifyInstanceLike {
|
|
37
37
|
addHook: (name: 'onRequest' | 'preHandler', handler: (request: FastifyRequestLike, reply: FastifyReplyLike) => Promise<void> | void) => void;
|
|
38
38
|
}
|
|
39
|
-
declare function createFastifyPlugin(options:
|
|
39
|
+
declare function createFastifyPlugin(options: ServerOptions): (instance: FastifyInstanceLike) => Promise<void>;
|
|
40
40
|
|
|
41
|
-
declare function createFetchHandler(options:
|
|
41
|
+
declare function createFetchHandler(options: ServerOptions): FetchHandler;
|
|
42
42
|
|
|
43
43
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
44
|
-
type
|
|
45
|
-
type
|
|
46
|
-
type MockResponse = unknown | MockResponseHandler;
|
|
44
|
+
type RequestHandler = (context: Context) => Response | Promise<Response> | unknown;
|
|
45
|
+
type RouteResponse = unknown | RequestHandler;
|
|
47
46
|
interface ResolvedMiddleware {
|
|
48
|
-
handle:
|
|
47
|
+
handle: MiddlewareHandler;
|
|
49
48
|
source: string;
|
|
50
49
|
index: number;
|
|
51
50
|
}
|
|
@@ -55,7 +54,7 @@ interface ResolvedRoute {
|
|
|
55
54
|
method: HttpMethod;
|
|
56
55
|
tokens: RouteToken[];
|
|
57
56
|
score: number[];
|
|
58
|
-
handler:
|
|
57
|
+
handler: RouteResponse;
|
|
59
58
|
middlewares?: ResolvedMiddleware[];
|
|
60
59
|
status?: number;
|
|
61
60
|
headers?: Record<string, string>;
|
|
@@ -66,7 +65,7 @@ type RouteTable = ResolvedRoute[];
|
|
|
66
65
|
|
|
67
66
|
type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
|
|
68
67
|
|
|
69
|
-
interface
|
|
68
|
+
interface FetchServerOptions {
|
|
70
69
|
dir?: DirInput;
|
|
71
70
|
prefix?: string;
|
|
72
71
|
include?: RegExp | RegExp[];
|
|
@@ -81,15 +80,15 @@ interface MokupFetchServerOptions {
|
|
|
81
80
|
port?: number;
|
|
82
81
|
root?: string;
|
|
83
82
|
}
|
|
84
|
-
type
|
|
83
|
+
type FetchServerOptionsInput = FetchServerOptions | FetchServerOptions[];
|
|
85
84
|
|
|
86
|
-
interface
|
|
85
|
+
interface FetchServer {
|
|
87
86
|
fetch: (request: Request) => Promise<Response>;
|
|
88
87
|
refresh: () => Promise<void>;
|
|
89
88
|
getRoutes: () => RouteTable;
|
|
90
89
|
close?: () => Promise<void>;
|
|
91
90
|
}
|
|
92
|
-
declare function createFetchServer(options?:
|
|
91
|
+
declare function createFetchServer(options?: FetchServerOptionsInput): Promise<FetchServer>;
|
|
93
92
|
|
|
94
93
|
interface HonoContextLike {
|
|
95
94
|
req: {
|
|
@@ -104,7 +103,7 @@ interface HonoRouteLike {
|
|
|
104
103
|
method: string;
|
|
105
104
|
handler: HonoMiddleware;
|
|
106
105
|
}
|
|
107
|
-
declare function createHonoMiddleware(options:
|
|
106
|
+
declare function createHonoMiddleware(options: ServerOptions): HonoMiddleware & {
|
|
108
107
|
routes: HonoRouteLike[];
|
|
109
108
|
};
|
|
110
109
|
|
|
@@ -119,13 +118,13 @@ interface KoaContextLike {
|
|
|
119
118
|
set: (header: Record<string, string>) => void;
|
|
120
119
|
}
|
|
121
120
|
type KoaNext = () => Promise<unknown>;
|
|
122
|
-
declare function createKoaMiddleware(options:
|
|
121
|
+
declare function createKoaMiddleware(options: ServerOptions): (ctx: KoaContextLike, next: KoaNext) => Promise<void>;
|
|
123
122
|
|
|
124
|
-
interface
|
|
123
|
+
interface FetchWorker {
|
|
125
124
|
fetch: (request: Request) => Promise<Response>;
|
|
126
125
|
}
|
|
127
|
-
declare function createMokupWorker(input: string): Promise<
|
|
128
|
-
declare function createMokupWorker(input: Exclude<
|
|
126
|
+
declare function createMokupWorker(input: string): Promise<FetchWorker>;
|
|
127
|
+
declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
|
|
129
128
|
|
|
130
|
-
export { FetchHandler,
|
|
131
|
-
export type {
|
|
129
|
+
export { FetchHandler, ServerOptions, WorkerInput, createConnectMiddleware, createExpressMiddleware, createFastifyPlugin, createFetchHandler, createFetchServer, createHonoMiddleware, createKoaMiddleware, createMokupWorker };
|
|
130
|
+
export type { FetchServer, FetchServerOptions, FetchServerOptionsInput };
|
package/dist/index.mjs
CHANGED
|
@@ -186,6 +186,18 @@ function applyRouteOverrides(response, route) {
|
|
|
186
186
|
}
|
|
187
187
|
return new Response(response.body, { status, headers });
|
|
188
188
|
}
|
|
189
|
+
function resolveResponse(value, fallback) {
|
|
190
|
+
if (value instanceof Response) {
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
if (value && typeof value === "object" && "res" in value) {
|
|
194
|
+
const resolved = value.res;
|
|
195
|
+
if (resolved instanceof Response) {
|
|
196
|
+
return resolved;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return fallback;
|
|
200
|
+
}
|
|
189
201
|
function normalizeHandlerValue(c, value) {
|
|
190
202
|
if (value instanceof Response) {
|
|
191
203
|
return value;
|
|
@@ -221,17 +233,19 @@ function createRouteHandler(route) {
|
|
|
221
233
|
function createFinalizeMiddleware(route) {
|
|
222
234
|
return async (c, next) => {
|
|
223
235
|
const response = await next();
|
|
224
|
-
const resolved = response
|
|
236
|
+
const resolved = resolveResponse(response, c.res);
|
|
225
237
|
if (route.delay && route.delay > 0) {
|
|
226
238
|
await delay(route.delay);
|
|
227
239
|
}
|
|
228
|
-
|
|
240
|
+
const overridden = applyRouteOverrides(resolved, route);
|
|
241
|
+
c.res = overridden;
|
|
242
|
+
return overridden;
|
|
229
243
|
};
|
|
230
244
|
}
|
|
231
245
|
function wrapMiddleware(handler) {
|
|
232
246
|
return async (c, next) => {
|
|
233
247
|
const response = await handler(c, next);
|
|
234
|
-
return response
|
|
248
|
+
return resolveResponse(response, c.res);
|
|
235
249
|
};
|
|
236
250
|
}
|
|
237
251
|
function createHonoApp(routes) {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { RuntimeOptions, Manifest, ModuleMap } from '@mokup/runtime';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
interface ServerOptions extends RuntimeOptions {
|
|
4
4
|
onNotFound?: 'next' | 'response';
|
|
5
5
|
}
|
|
6
6
|
type FetchHandler = (request: Request) => Promise<Response | null>;
|
|
7
|
-
interface
|
|
7
|
+
interface WorkerBundle {
|
|
8
8
|
manifest: Manifest;
|
|
9
9
|
moduleMap?: ModuleMap;
|
|
10
10
|
moduleBase?: string | URL;
|
|
11
11
|
onNotFound?: 'next' | 'response';
|
|
12
12
|
}
|
|
13
|
-
type
|
|
13
|
+
type WorkerInput = string | Manifest | WorkerBundle;
|
|
14
14
|
|
|
15
|
-
export type { FetchHandler as F,
|
|
15
|
+
export type { FetchHandler as F, ServerOptions as S, WorkerInput as W, WorkerBundle as a };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { RuntimeOptions, Manifest, ModuleMap } from '@mokup/runtime';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
interface ServerOptions extends RuntimeOptions {
|
|
4
4
|
onNotFound?: 'next' | 'response';
|
|
5
5
|
}
|
|
6
6
|
type FetchHandler = (request: Request) => Promise<Response | null>;
|
|
7
|
-
interface
|
|
7
|
+
interface WorkerBundle {
|
|
8
8
|
manifest: Manifest;
|
|
9
9
|
moduleMap?: ModuleMap;
|
|
10
10
|
moduleBase?: string | URL;
|
|
11
11
|
onNotFound?: 'next' | 'response';
|
|
12
12
|
}
|
|
13
|
-
type
|
|
13
|
+
type WorkerInput = string | Manifest | WorkerBundle;
|
|
14
14
|
|
|
15
|
-
export type { FetchHandler as F,
|
|
15
|
+
export type { FetchHandler as F, ServerOptions as S, WorkerInput as W, WorkerBundle as a };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { RuntimeOptions, Manifest, ModuleMap } from '@mokup/runtime';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
interface ServerOptions extends RuntimeOptions {
|
|
4
4
|
onNotFound?: 'next' | 'response';
|
|
5
5
|
}
|
|
6
6
|
type FetchHandler = (request: Request) => Promise<Response | null>;
|
|
7
|
-
interface
|
|
7
|
+
interface WorkerBundle {
|
|
8
8
|
manifest: Manifest;
|
|
9
9
|
moduleMap?: ModuleMap;
|
|
10
10
|
moduleBase?: string | URL;
|
|
11
11
|
onNotFound?: 'next' | 'response';
|
|
12
12
|
}
|
|
13
|
-
type
|
|
13
|
+
type WorkerInput = string | Manifest | WorkerBundle;
|
|
14
14
|
|
|
15
|
-
export type { FetchHandler as F,
|
|
15
|
+
export type { FetchHandler as F, ServerOptions as S, WorkerInput as W, WorkerBundle as a };
|
package/dist/worker.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { W as WorkerInput } from './shared/server.DNITwCtQ.cjs';
|
|
2
2
|
import '@mokup/runtime';
|
|
3
3
|
|
|
4
|
-
interface
|
|
4
|
+
interface FetchWorker {
|
|
5
5
|
fetch: (request: Request) => Promise<Response>;
|
|
6
6
|
}
|
|
7
|
-
declare function createMokupWorker(input: Exclude<
|
|
7
|
+
declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
|
|
8
8
|
|
|
9
9
|
export { createMokupWorker };
|
|
10
|
-
export type {
|
|
10
|
+
export type { FetchWorker };
|
package/dist/worker.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { W as WorkerInput } from './shared/server.DNITwCtQ.mjs';
|
|
2
2
|
import '@mokup/runtime';
|
|
3
3
|
|
|
4
|
-
interface
|
|
4
|
+
interface FetchWorker {
|
|
5
5
|
fetch: (request: Request) => Promise<Response>;
|
|
6
6
|
}
|
|
7
|
-
declare function createMokupWorker(input: Exclude<
|
|
7
|
+
declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
|
|
8
8
|
|
|
9
9
|
export { createMokupWorker };
|
|
10
|
-
export type {
|
|
10
|
+
export type { FetchWorker };
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { W as WorkerInput } from './shared/server.DNITwCtQ.js';
|
|
2
2
|
import '@mokup/runtime';
|
|
3
3
|
|
|
4
|
-
interface
|
|
4
|
+
interface FetchWorker {
|
|
5
5
|
fetch: (request: Request) => Promise<Response>;
|
|
6
6
|
}
|
|
7
|
-
declare function createMokupWorker(input: Exclude<
|
|
7
|
+
declare function createMokupWorker(input: Exclude<WorkerInput, string>): FetchWorker;
|
|
8
8
|
|
|
9
9
|
export { createMokupWorker };
|
|
10
|
-
export type {
|
|
10
|
+
export type { FetchWorker };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mokup/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "Server adapters for @mokup/runtime.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://mokup.icebreaker.top",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@mokup/
|
|
36
|
-
"@mokup/runtime": "0.
|
|
37
|
-
"@mokup/
|
|
35
|
+
"@mokup/playground": "0.0.6",
|
|
36
|
+
"@mokup/runtime": "1.0.0",
|
|
37
|
+
"@mokup/shared": "1.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@hono/node-server": "^1.19.9",
|