@kaito-http/core 2.2.6 → 2.2.7
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.
|
@@ -4,18 +4,24 @@ import { z, ZodTypeAny } from 'zod';
|
|
|
4
4
|
import { KaitoRequest } from './req';
|
|
5
5
|
import { KaitoResponse } from './res';
|
|
6
6
|
import { Method, NormalizePath } from './util';
|
|
7
|
+
declare type ExtractRouteParams<T extends string> = string extends T ? Record<string, string> : T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
8
|
+
[k in Param | keyof ExtractRouteParams<Rest>]: string;
|
|
9
|
+
} : T extends `${string}:${infer Param}` ? {
|
|
10
|
+
[k in Param]: string;
|
|
11
|
+
} : {};
|
|
7
12
|
export declare type GetContext<T> = (req: KaitoRequest, res: KaitoResponse) => Promise<T>;
|
|
8
13
|
declare type Never = [never];
|
|
9
14
|
export declare function createGetContext<T>(getContext: GetContext<T>): GetContext<T>;
|
|
10
15
|
export declare type InferContext<T> = T extends GetContext<infer Value> ? Value : never;
|
|
11
|
-
export declare type ContextWithInput<Ctx, Input> = {
|
|
16
|
+
export declare type ContextWithInput<Ctx, Params extends Record<string, string>, Input> = {
|
|
12
17
|
ctx: Ctx;
|
|
18
|
+
params: Params;
|
|
13
19
|
input: Input;
|
|
14
20
|
};
|
|
15
21
|
declare type Values<T> = T[keyof T];
|
|
16
|
-
export declare type Proc<Ctx, Result, Input extends z.ZodTypeAny | Never = Never> = {
|
|
22
|
+
export declare type Proc<Ctx, Result, Params extends Record<string, string> = Record<never, string>, Input extends z.ZodTypeAny | Never = Never> = {
|
|
17
23
|
input?: Input;
|
|
18
|
-
run(arg: ContextWithInput<Ctx, Input extends ZodTypeAny ? z.infer<Input> : undefined>): Promise<Result>;
|
|
24
|
+
run(arg: ContextWithInput<Ctx, Params, Input extends ZodTypeAny ? z.infer<Input> : undefined>): Promise<Result>;
|
|
19
25
|
};
|
|
20
26
|
export interface RouterProc<Path extends string, M extends Method> {
|
|
21
27
|
method: M;
|
|
@@ -23,7 +29,7 @@ export interface RouterProc<Path extends string, M extends Method> {
|
|
|
23
29
|
pattern: RegExp;
|
|
24
30
|
}
|
|
25
31
|
export declare type AnyProcs<Ctx> = {
|
|
26
|
-
[Path in string]: Proc<Ctx, unknown, z.ZodTypeAny> & RouterProc<Path, Method>;
|
|
32
|
+
[Path in string]: Proc<Ctx, unknown, Record<string, string>, z.ZodTypeAny> & RouterProc<Path, Method>;
|
|
27
33
|
};
|
|
28
34
|
export declare type AnyRouter<Ctx> = Router<Ctx, AnyProcs<Ctx>>;
|
|
29
35
|
export declare class Router<Ctx, Procs extends AnyProcs<Ctx>> {
|
|
@@ -32,22 +38,22 @@ export declare class Router<Ctx, Procs extends AnyProcs<Ctx>> {
|
|
|
32
38
|
private static patternize;
|
|
33
39
|
constructor(procs: Procs);
|
|
34
40
|
getProcs(): Procs;
|
|
35
|
-
find(method: Method, url: string): (Proc<Ctx, unknown, z.ZodTypeAny> & RouterProc<string, Method>) | null;
|
|
41
|
+
find(method: Method, url: string): (Proc<Ctx, unknown, Record<string, string>, z.ZodTypeAny> & RouterProc<string, Method>) | null;
|
|
36
42
|
private readonly create;
|
|
37
43
|
readonly merge: <Prefix extends string, NewCtx, NewProcs extends AnyProcs<NewCtx>>(prefix: (Prefix extends `${infer U}/` ? U : Prefix) extends `/${infer U_1}` ? `/${U_1}` : `/${Prefix extends `${infer U}/` ? U : Prefix}`, router: Router<NewCtx, NewProcs>) => Router<NewCtx & Ctx, Procs & { [P in Extract<keyof NewProcs, string> as `/${Prefix}${P}`]: Omit<NewProcs[P], "path"> & {
|
|
38
44
|
path: P;
|
|
39
45
|
}; }>;
|
|
40
|
-
readonly get: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "GET">>>;
|
|
41
|
-
readonly post: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "POST">>>;
|
|
42
|
-
readonly put: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "PUT">>>;
|
|
43
|
-
readonly patch: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "PATCH">>>;
|
|
44
|
-
readonly delete: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "DELETE">>>;
|
|
45
|
-
readonly head: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "HEAD">>>;
|
|
46
|
-
readonly options: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "OPTIONS">>>;
|
|
47
|
-
readonly connect: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "CONNECT">>>;
|
|
48
|
-
readonly trace: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "TRACE">>>;
|
|
49
|
-
readonly acl: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "ACL">>>;
|
|
50
|
-
readonly bind: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "BIND">>>;
|
|
46
|
+
readonly get: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "GET">>>;
|
|
47
|
+
readonly post: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "POST">>>;
|
|
48
|
+
readonly put: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "PUT">>>;
|
|
49
|
+
readonly patch: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "PATCH">>>;
|
|
50
|
+
readonly delete: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "DELETE">>>;
|
|
51
|
+
readonly head: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "HEAD">>>;
|
|
52
|
+
readonly options: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "OPTIONS">>>;
|
|
53
|
+
readonly connect: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "CONNECT">>>;
|
|
54
|
+
readonly trace: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "TRACE">>>;
|
|
55
|
+
readonly acl: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "ACL">>>;
|
|
56
|
+
readonly bind: <Path extends string, Result, Input extends z.ZodTypeAny>(path: (Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, proc: Proc<Ctx, Result, ExtractRouteParams<Path>, Input>) => Router<Ctx, Procs & Record<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, Proc<Ctx, Result, ExtractRouteParams<Path>, Input> & RouterProc<(Path extends `${infer U}/` ? U : Path) extends `/${infer U_1}` ? `/${U_1}` : `/${Path extends `${infer U}/` ? U : Path}`, "BIND">>>;
|
|
51
57
|
}
|
|
52
58
|
export declare class KaitoError extends Error {
|
|
53
59
|
readonly status: number;
|
|
@@ -174,6 +174,8 @@ function _getInput() {
|
|
|
174
174
|
|
|
175
175
|
class KaitoRequest {
|
|
176
176
|
constructor(raw) {
|
|
177
|
+
_defineProperty(this, "_url", null);
|
|
178
|
+
|
|
177
179
|
this.raw = raw;
|
|
178
180
|
}
|
|
179
181
|
|
|
@@ -184,7 +186,12 @@ class KaitoRequest {
|
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
get url() {
|
|
187
|
-
|
|
189
|
+
if (this._url) {
|
|
190
|
+
return this._url;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this._url = new URL(this.fullURL);
|
|
194
|
+
return this._url;
|
|
188
195
|
}
|
|
189
196
|
|
|
190
197
|
get method() {
|
|
@@ -355,7 +362,7 @@ function createServer(config) {
|
|
|
355
362
|
try {
|
|
356
363
|
var _handler$input, _yield$getInput;
|
|
357
364
|
|
|
358
|
-
var handler = config.router.find(req.method, req.url
|
|
365
|
+
var handler = config.router.find(req.method, req.raw.url);
|
|
359
366
|
|
|
360
367
|
if (!handler) {
|
|
361
368
|
throw new KaitoError(404, "Cannot ".concat(req.method, " this route."));
|
|
@@ -365,7 +372,8 @@ function createServer(config) {
|
|
|
365
372
|
var context = yield config.getContext(req, res);
|
|
366
373
|
var data = yield handler.run({
|
|
367
374
|
ctx: context,
|
|
368
|
-
input
|
|
375
|
+
input,
|
|
376
|
+
params: {}
|
|
369
377
|
});
|
|
370
378
|
res.json({
|
|
371
379
|
success: true,
|
|
@@ -174,6 +174,8 @@ function _getInput() {
|
|
|
174
174
|
|
|
175
175
|
class KaitoRequest {
|
|
176
176
|
constructor(raw) {
|
|
177
|
+
_defineProperty(this, "_url", null);
|
|
178
|
+
|
|
177
179
|
this.raw = raw;
|
|
178
180
|
}
|
|
179
181
|
|
|
@@ -184,7 +186,12 @@ class KaitoRequest {
|
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
get url() {
|
|
187
|
-
|
|
189
|
+
if (this._url) {
|
|
190
|
+
return this._url;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
this._url = new URL(this.fullURL);
|
|
194
|
+
return this._url;
|
|
188
195
|
}
|
|
189
196
|
|
|
190
197
|
get method() {
|
|
@@ -355,7 +362,7 @@ function createServer(config) {
|
|
|
355
362
|
try {
|
|
356
363
|
var _handler$input, _yield$getInput;
|
|
357
364
|
|
|
358
|
-
var handler = config.router.find(req.method, req.url
|
|
365
|
+
var handler = config.router.find(req.method, req.raw.url);
|
|
359
366
|
|
|
360
367
|
if (!handler) {
|
|
361
368
|
throw new KaitoError(404, "Cannot ".concat(req.method, " this route."));
|
|
@@ -365,7 +372,8 @@ function createServer(config) {
|
|
|
365
372
|
var context = yield config.getContext(req, res);
|
|
366
373
|
var data = yield handler.run({
|
|
367
374
|
ctx: context,
|
|
368
|
-
input
|
|
375
|
+
input,
|
|
376
|
+
params: {}
|
|
369
377
|
});
|
|
370
378
|
res.json({
|
|
371
379
|
success: true,
|
|
@@ -165,6 +165,8 @@ function _getInput() {
|
|
|
165
165
|
|
|
166
166
|
class KaitoRequest {
|
|
167
167
|
constructor(raw) {
|
|
168
|
+
_defineProperty(this, "_url", null);
|
|
169
|
+
|
|
168
170
|
this.raw = raw;
|
|
169
171
|
}
|
|
170
172
|
|
|
@@ -175,7 +177,12 @@ class KaitoRequest {
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
get url() {
|
|
178
|
-
|
|
180
|
+
if (this._url) {
|
|
181
|
+
return this._url;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
this._url = new URL(this.fullURL);
|
|
185
|
+
return this._url;
|
|
179
186
|
}
|
|
180
187
|
|
|
181
188
|
get method() {
|
|
@@ -346,7 +353,7 @@ function createServer(config) {
|
|
|
346
353
|
try {
|
|
347
354
|
var _handler$input, _yield$getInput;
|
|
348
355
|
|
|
349
|
-
var handler = config.router.find(req.method, req.url
|
|
356
|
+
var handler = config.router.find(req.method, req.raw.url);
|
|
350
357
|
|
|
351
358
|
if (!handler) {
|
|
352
359
|
throw new KaitoError(404, "Cannot ".concat(req.method, " this route."));
|
|
@@ -356,7 +363,8 @@ function createServer(config) {
|
|
|
356
363
|
var context = yield config.getContext(req, res);
|
|
357
364
|
var data = yield handler.run({
|
|
358
365
|
ctx: context,
|
|
359
|
-
input
|
|
366
|
+
input,
|
|
367
|
+
params: {}
|
|
360
368
|
});
|
|
361
369
|
res.json({
|
|
362
370
|
success: true,
|