@bepalo/router 1.6.21 → 1.8.24
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/README.md +11 -10
- package/dist/cjs/framework.d.ts +33 -0
- package/dist/cjs/framework.d.ts.map +1 -0
- package/dist/cjs/framework.js +269 -0
- package/dist/cjs/framework.js.map +1 -0
- package/dist/cjs/helpers.d.ts +6 -6
- package/dist/cjs/helpers.d.ts.map +1 -1
- package/dist/cjs/helpers.js +32 -24
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/middlewares.d.ts +29 -18
- package/dist/cjs/middlewares.d.ts.map +1 -1
- package/dist/cjs/middlewares.js +21 -11
- package/dist/cjs/middlewares.js.map +1 -1
- package/dist/cjs/router.d.ts +10 -2
- package/dist/cjs/router.d.ts.map +1 -1
- package/dist/cjs/router.js +105 -79
- package/dist/cjs/router.js.map +1 -1
- package/dist/cjs/tree.d.ts.map +1 -1
- package/dist/cjs/tree.js +22 -30
- package/dist/cjs/tree.js.map +1 -1
- package/dist/framework.d.ts +33 -0
- package/dist/framework.d.ts.map +1 -0
- package/dist/framework.js +269 -0
- package/dist/framework.js.map +1 -0
- package/dist/helpers.d.ts +6 -6
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +32 -24
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/middlewares.d.ts +29 -18
- package/dist/middlewares.d.ts.map +1 -1
- package/dist/middlewares.js +21 -11
- package/dist/middlewares.js.map +1 -1
- package/dist/router.d.ts +10 -2
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +105 -79
- package/dist/router.js.map +1 -1
- package/dist/tree.d.ts.map +1 -1
- package/dist/tree.js +22 -30
- package/dist/tree.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
[](https://github.com/bepalo/router/actions/workflows/ci.yaml)
|
|
5
5
|
[](https://github.com/bepalo/router/actions/workflows/testing.yaml)
|
|
6
6
|
[](LICENSE)
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
<!--  -->
|
|
8
9
|
|
|
9
10
|
[](test-result.md)
|
|
10
11
|
|
|
@@ -14,15 +15,9 @@
|
|
|
14
15
|
|
|
15
16
|
Please refer to the [change-log](CHANGELOG.md).
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
## Docs
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
router.handle("ALL /.**", ...); // HEAD|OPTIONS|GET|POST|PUT|PATCH|DELETE
|
|
21
|
-
router.handle("CRUD /api/.**", ...); // GET|POST|PUT|PATCH|DELETE
|
|
22
|
-
// instead of
|
|
23
|
-
router.handle(["HEAD /", "OPTIONS /", ...], ...); // "ALL /"
|
|
24
|
-
router.handle(["GET /api", "POST /api", ...], ...); // "CRUD /api"
|
|
25
|
-
```
|
|
20
|
+
- [Framework](docs/router-framework.md).
|
|
26
21
|
|
|
27
22
|
## 📑 Table of Contents
|
|
28
23
|
|
|
@@ -74,6 +69,7 @@ router.handle(["GET /api", "POST /api", ...], ...); // "CRUD /api"
|
|
|
74
69
|
- 🧩 **Composable Router Architecture** - Append one router to another with a path prefix.
|
|
75
70
|
- 🛠️ **Built-in Helper Utilities** - Built-in response helpers (json, html, parseBody, upload, etc.)
|
|
76
71
|
- 🔐 **Middleware Integration** - CORS, rate limiting, authentication helpers
|
|
72
|
+
- 🔐 **Normalized pathname option** - An option to normalize pathnames.
|
|
77
73
|
|
|
78
74
|
## 🚀 Get Started
|
|
79
75
|
|
|
@@ -235,6 +231,10 @@ router.handle("GET /", () =>
|
|
|
235
231
|
);
|
|
236
232
|
router.handle("GET /status", () => status(200));
|
|
237
233
|
|
|
234
|
+
// trailing slash matters unless normalizeTrailingSlash option is set
|
|
235
|
+
router.handle("GET /res/", () => text("/res/"));
|
|
236
|
+
router.handle("GET /res", () => text("/res"));
|
|
237
|
+
|
|
238
238
|
// Sample sub-route `/api/user`
|
|
239
239
|
////////////////////////////////////////
|
|
240
240
|
// eg. inside routes/api/user.ts
|
|
@@ -462,6 +462,7 @@ interface RouterConfig<Context extends RouterContext> {
|
|
|
462
462
|
defaultCatcher?: Handler<Context>; // Global error handler
|
|
463
463
|
defaultFallback?: Handler<Context>; // Global fallback handler
|
|
464
464
|
enable?: HandlerEnable; // Handler types enable/disable
|
|
465
|
+
normalizeTrailingSlash?: boolean; // treat '/abc/' and '/abc' as the same
|
|
465
466
|
}
|
|
466
467
|
```
|
|
467
468
|
|
|
@@ -524,7 +525,7 @@ interface HandlerOptions {
|
|
|
524
525
|
#### Router Composition
|
|
525
526
|
|
|
526
527
|
```ts
|
|
527
|
-
// Append another router with a prefix
|
|
528
|
+
// Append another router with a prefix. Does not merge router configurations
|
|
528
529
|
router.append(
|
|
529
530
|
baseUrl: `/${string}`,
|
|
530
531
|
router: Router<Context>,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Router, { RouterConfig, RouterContext } from "./router";
|
|
2
|
+
import type { Handler, HttpMethod, Pipeline, CTXError } from "./types";
|
|
3
|
+
export declare const isDeno: boolean;
|
|
4
|
+
export declare const DenoProxy: any;
|
|
5
|
+
export type UCHandlerType = "FILTER" | "HOOK" | "HANDLER" | "FALLBACK" | "CATCHER" | "AFTER";
|
|
6
|
+
export type RouterHandlers<CommonXContext = {}, MethodContexts extends Partial<Record<HttpMethod | "ALL" | "CRUD", Record<string, any>>> = {}> = {
|
|
7
|
+
[K in HttpMethod | "ALL" | "CRUD" as K]?: {
|
|
8
|
+
[H in UCHandlerType as H]?: H extends "CATCHER" ? Handler<CommonXContext & CTXError & MethodContexts[K]> | Pipeline<CommonXContext & CTXError & MethodContexts[K]> : Handler<CommonXContext & MethodContexts[K]> | Pipeline<CommonXContext & MethodContexts[K]>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export interface RouterFrameworkConfig<Context extends RouterContext = RouterContext> extends RouterConfig<Context> {
|
|
12
|
+
rootPath?: string;
|
|
13
|
+
filterNode?: (node: DirWalkNode) => boolean;
|
|
14
|
+
processNode?: (node: DirWalkNode) => void;
|
|
15
|
+
onDir?: (node: DirWalkNode) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare class RouterFramework<EXTContext = {}, Context extends RouterContext<EXTContext> = RouterContext<EXTContext>> extends Router<Context> {
|
|
18
|
+
#private;
|
|
19
|
+
get loading(): boolean;
|
|
20
|
+
get loaded(): boolean;
|
|
21
|
+
constructor(config?: RouterFrameworkConfig<Context>);
|
|
22
|
+
load(): Promise<RouterFramework<Context>>;
|
|
23
|
+
}
|
|
24
|
+
export interface DirWalkNode {
|
|
25
|
+
type: string;
|
|
26
|
+
name: string;
|
|
27
|
+
path: string;
|
|
28
|
+
parent: string;
|
|
29
|
+
fullPath: string;
|
|
30
|
+
relativePath: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function walk(dir: string, rootPath?: string): AsyncGenerator<DirWalkNode>;
|
|
33
|
+
//# sourceMappingURL=framework.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework.d.ts","sourceRoot":"","sources":["../../src/framework.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAEb,YAAY,EACZ,aAAa,EACd,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,OAAO,EAEP,UAAU,EAEV,QAAQ,EACR,QAAQ,EACT,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,MAAM,SAAuB,CAAC;AAC3C,eAAO,MAAM,SAAS,KAAyC,CAAC;AAShE,MAAM,MAAM,aAAa,GACrB,QAAQ,GACR,MAAM,GACN,SAAS,GACT,UAAU,GACV,SAAS,GACT,OAAO,CAAC;AAEZ,MAAM,MAAM,cAA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AC;IAU7C,IAAI,IAAI,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;CAgFhD;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,wBAAuB,IAAI,CACzB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,cAAc,CAAC,WAAW,CAAC,CAqC7B"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
45
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
46
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
47
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
48
|
+
};
|
|
49
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
50
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
51
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
52
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
53
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
54
|
+
};
|
|
55
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
56
|
+
var t = {};
|
|
57
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
58
|
+
t[p] = s[p];
|
|
59
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
60
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
61
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
62
|
+
t[p[i]] = s[p[i]];
|
|
63
|
+
}
|
|
64
|
+
return t;
|
|
65
|
+
};
|
|
66
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
67
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
68
|
+
var m = o[Symbol.asyncIterator], i;
|
|
69
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
70
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
71
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
72
|
+
};
|
|
73
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
74
|
+
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
|
75
|
+
var i, p;
|
|
76
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
77
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v; } : f; }
|
|
78
|
+
};
|
|
79
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
80
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
81
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
82
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
83
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
84
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
85
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
86
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
87
|
+
function fulfill(value) { resume("next", value); }
|
|
88
|
+
function reject(value) { resume("throw", value); }
|
|
89
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
90
|
+
};
|
|
91
|
+
var _RouterFramework_rootPath, _RouterFramework_filterNode, _RouterFramework_processNode, _RouterFramework_onDir, _RouterFramework_loading, _RouterFramework_loaded;
|
|
92
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
93
|
+
exports.RouterFramework = exports.DenoProxy = exports.isDeno = void 0;
|
|
94
|
+
exports.walk = walk;
|
|
95
|
+
const router_1 = __importStar(require("./router"));
|
|
96
|
+
exports.isDeno = "Deno" in globalThis;
|
|
97
|
+
exports.DenoProxy = exports.isDeno ? globalThis.Deno : {};
|
|
98
|
+
const defaultValidExtensions = [".ts", ".js", ".tsx", ".jsx"];
|
|
99
|
+
const defaultNodeFilter = (node) => defaultValidExtensions.some((ext) => node.name.endsWith(ext));
|
|
100
|
+
const defaultNodeProcessor = (node) => {
|
|
101
|
+
const extensionIndex = node.name.lastIndexOf(".");
|
|
102
|
+
if (extensionIndex !== -1)
|
|
103
|
+
node.name = node.name.slice(0, extensionIndex);
|
|
104
|
+
};
|
|
105
|
+
class RouterFramework extends router_1.default {
|
|
106
|
+
get loading() {
|
|
107
|
+
return __classPrivateFieldGet(this, _RouterFramework_loading, "f");
|
|
108
|
+
}
|
|
109
|
+
get loaded() {
|
|
110
|
+
return __classPrivateFieldGet(this, _RouterFramework_loaded, "f");
|
|
111
|
+
}
|
|
112
|
+
constructor(config) {
|
|
113
|
+
const _a = config !== null && config !== void 0 ? config : {}, { rootPath, filterNode, processNode, onDir } = _a, baseConfig = __rest(_a, ["rootPath", "filterNode", "processNode", "onDir"]);
|
|
114
|
+
super(baseConfig);
|
|
115
|
+
_RouterFramework_rootPath.set(this, void 0);
|
|
116
|
+
_RouterFramework_filterNode.set(this, void 0);
|
|
117
|
+
_RouterFramework_processNode.set(this, void 0);
|
|
118
|
+
_RouterFramework_onDir.set(this, void 0);
|
|
119
|
+
_RouterFramework_loading.set(this, false);
|
|
120
|
+
_RouterFramework_loaded.set(this, false);
|
|
121
|
+
__classPrivateFieldSet(this, _RouterFramework_rootPath, rootPath || "./routes", "f");
|
|
122
|
+
__classPrivateFieldSet(this, _RouterFramework_filterNode, filterNode !== null && filterNode !== void 0 ? filterNode : defaultNodeFilter, "f");
|
|
123
|
+
__classPrivateFieldSet(this, _RouterFramework_processNode, processNode !== null && processNode !== void 0 ? processNode : defaultNodeProcessor, "f");
|
|
124
|
+
__classPrivateFieldSet(this, _RouterFramework_onDir, onDir, "f");
|
|
125
|
+
}
|
|
126
|
+
load() {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
var _a, e_1, _b, _c;
|
|
129
|
+
if (__classPrivateFieldGet(this, _RouterFramework_loading, "f") || __classPrivateFieldGet(this, _RouterFramework_loaded, "f")) {
|
|
130
|
+
throw new Error("RouterFramework already loading or loaded");
|
|
131
|
+
}
|
|
132
|
+
__classPrivateFieldSet(this, _RouterFramework_loading, true, "f");
|
|
133
|
+
try {
|
|
134
|
+
for (var _d = true, _e = __asyncValues(walk(__classPrivateFieldGet(this, _RouterFramework_rootPath, "f"))), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
135
|
+
_c = _f.value;
|
|
136
|
+
_d = false;
|
|
137
|
+
let node = _c;
|
|
138
|
+
if (node.type !== "dir") {
|
|
139
|
+
let handlersImp;
|
|
140
|
+
let handlers;
|
|
141
|
+
try {
|
|
142
|
+
handlersImp = yield Promise.resolve(`${exports.isDeno ? `file://${node.fullPath}` : node.fullPath}`).then(s => __importStar(require(s)));
|
|
143
|
+
handlers = handlersImp === null || handlersImp === void 0 ? void 0 : handlersImp.default;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error(`Failed to import route at ${node.fullPath}:`, error);
|
|
147
|
+
}
|
|
148
|
+
// filter the node
|
|
149
|
+
if (!handlers || !(__classPrivateFieldGet(this, _RouterFramework_filterNode, "f") && __classPrivateFieldGet(this, _RouterFramework_filterNode, "f").call(this, node))) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
// process the node
|
|
153
|
+
if (__classPrivateFieldGet(this, _RouterFramework_processNode, "f"))
|
|
154
|
+
__classPrivateFieldGet(this, _RouterFramework_processNode, "f").call(this, node);
|
|
155
|
+
const name = node.name;
|
|
156
|
+
let path;
|
|
157
|
+
switch (name) {
|
|
158
|
+
case "[$$]":
|
|
159
|
+
path = `${node.parent ? "/" + node.parent + "/" : "/"}.**`;
|
|
160
|
+
break;
|
|
161
|
+
case "($$)":
|
|
162
|
+
path = `${node.parent ? "/" + node.parent + "/" : "/"}**`;
|
|
163
|
+
break;
|
|
164
|
+
case "[$]":
|
|
165
|
+
path = `${node.parent ? "/" + node.parent + "/" : "/"}.*`;
|
|
166
|
+
break;
|
|
167
|
+
case "($)":
|
|
168
|
+
path = `${node.parent ? "/" + node.parent + "/" : "/"}*`;
|
|
169
|
+
break;
|
|
170
|
+
case "index":
|
|
171
|
+
path = "/" + node.parent;
|
|
172
|
+
break;
|
|
173
|
+
default:
|
|
174
|
+
path = `${node.parent ? "/" + node.parent + "/" : "/"}${name}`;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
// replace (param) with :param
|
|
178
|
+
path = path.replace(/\[([^\/]+?)\]/g, ":$1");
|
|
179
|
+
// set handlers
|
|
180
|
+
for (const [method, methodHandlers] of Object.entries(handlers)) {
|
|
181
|
+
for (const [uchandlerType, pipeline] of Object.entries(methodHandlers)) {
|
|
182
|
+
const handlerType = uchandlerType.toLowerCase();
|
|
183
|
+
if ((0, router_1.isValidHttpMethod)(method) ||
|
|
184
|
+
method === "ALL" ||
|
|
185
|
+
method === "CRUD") {
|
|
186
|
+
this.setRoutes(handlerType, `${method} ${path}`, pipeline);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
throw new Error(`Invalid http method '${method}'`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else if (__classPrivateFieldGet(this, _RouterFramework_onDir, "f")) {
|
|
195
|
+
__classPrivateFieldGet(this, _RouterFramework_onDir, "f").call(this, node);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
200
|
+
finally {
|
|
201
|
+
try {
|
|
202
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
203
|
+
}
|
|
204
|
+
finally { if (e_1) throw e_1.error; }
|
|
205
|
+
}
|
|
206
|
+
__classPrivateFieldSet(this, _RouterFramework_loading, false, "f");
|
|
207
|
+
__classPrivateFieldSet(this, _RouterFramework_loaded, true, "f");
|
|
208
|
+
return this;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.RouterFramework = RouterFramework;
|
|
213
|
+
_RouterFramework_rootPath = new WeakMap(), _RouterFramework_filterNode = new WeakMap(), _RouterFramework_processNode = new WeakMap(), _RouterFramework_onDir = new WeakMap(), _RouterFramework_loading = new WeakMap(), _RouterFramework_loaded = new WeakMap();
|
|
214
|
+
function walk(dir, rootPath) {
|
|
215
|
+
return __asyncGenerator(this, arguments, function* walk_1() {
|
|
216
|
+
var _a, e_2, _b, _c;
|
|
217
|
+
rootPath = rootPath || dir;
|
|
218
|
+
if (exports.isDeno) {
|
|
219
|
+
const { join, resolve, relative } = yield __await(Promise.resolve().then(() => __importStar(require("https://deno.land/std/path/mod.ts"))));
|
|
220
|
+
try {
|
|
221
|
+
for (var _d = true, _e = __asyncValues(exports.DenoProxy.readDir(dir)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
|
|
222
|
+
_c = _f.value;
|
|
223
|
+
_d = false;
|
|
224
|
+
const entry = _c;
|
|
225
|
+
const name = entry.name;
|
|
226
|
+
const parent = relative(rootPath, dir).replace(/\\/g, "/");
|
|
227
|
+
const path = join(dir, name).replace(/\\/g, "/");
|
|
228
|
+
const fullPath = resolve(dir, name).replace(/\\/g, "/");
|
|
229
|
+
const relativePath = relative(rootPath, path).replace(/\\/g, "/");
|
|
230
|
+
if (entry.isDirectory) {
|
|
231
|
+
yield yield __await({ type: "dir", name, path, parent, fullPath, relativePath });
|
|
232
|
+
yield __await(yield* __asyncDelegator(__asyncValues(walk(path, rootPath))));
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
yield yield __await({ type: "file", name, path, parent, fullPath, relativePath });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
240
|
+
finally {
|
|
241
|
+
try {
|
|
242
|
+
if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
|
|
243
|
+
}
|
|
244
|
+
finally { if (e_2) throw e_2.error; }
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
const fs = yield __await(Promise.resolve().then(() => __importStar(require("fs"))));
|
|
249
|
+
const { join, resolve, relative } = yield __await(Promise.resolve().then(() => __importStar(require("path"))));
|
|
250
|
+
for (const entry of yield __await(fs.promises.readdir(dir, {
|
|
251
|
+
withFileTypes: true,
|
|
252
|
+
}))) {
|
|
253
|
+
const name = entry.name;
|
|
254
|
+
const parent = relative(rootPath, dir).replace(/\\/g, "/");
|
|
255
|
+
const path = join(dir, name).replace(/\\/g, "/");
|
|
256
|
+
const fullPath = resolve(dir, name).replace(/\\/g, "/");
|
|
257
|
+
const relativePath = relative(rootPath, path).replace(/\\/g, "/");
|
|
258
|
+
if (entry.isDirectory()) {
|
|
259
|
+
yield yield __await({ type: "dir", name, path, parent, fullPath, relativePath });
|
|
260
|
+
yield __await(yield* __asyncDelegator(__asyncValues(walk(path, rootPath))));
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
yield yield __await({ type: "file", name, path, parent, fullPath, relativePath });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=framework.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework.js","sourceRoot":"","sources":["../../src/framework.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkLA,oBAwCC;AA1ND,mDAIkB;AAUL,QAAA,MAAM,GAAG,MAAM,IAAI,UAAU,CAAC;AAC9B,QAAA,SAAS,GAAG,cAAM,CAAC,CAAC,CAAE,UAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AAChE,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC9D,MAAM,iBAAiB,GAAG,CAAC,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,CAAC;gBAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBACjD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBACxD,MAAM,YAAY,GAAG,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBAClE,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;oBACxB,oBAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAA,CAAC;oBAClE,cAAA,KAAK,CAAC,CAAC,iBAAA,cAAA,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA,CAAA,CAAA,CAAC;gBAC9B,CAAC;qBAAM,CAAC;oBACN,oBAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAA,CAAC;gBACrE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CAAA"}
|
package/dist/cjs/helpers.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ export declare enum Status {
|
|
|
78
78
|
export declare function getHttpStatusText(code: number): string;
|
|
79
79
|
/**
|
|
80
80
|
* Creates a Response with the specified status code.
|
|
81
|
-
* Defaults to text/plain content-type if not provided in init.headers.
|
|
81
|
+
* Defaults to 'text/plain; charset=utf-8' content-type if not provided in init.headers.
|
|
82
82
|
* @param {number} status - The HTTP status code
|
|
83
83
|
* @param {string|null} [content] - The response body content
|
|
84
84
|
* @param {ResponseInit} [init] - Additional response initialization options
|
|
@@ -113,7 +113,7 @@ export declare const forward: <XContext = {}>(path: string, options?: {
|
|
|
113
113
|
}) => BoundHandler<XContext>;
|
|
114
114
|
/**
|
|
115
115
|
* Creates a text/plain Response.
|
|
116
|
-
* Defaults to status 200 and text/plain content-type if not specified.
|
|
116
|
+
* Defaults to status 200 and 'text/plain; charset=utf-8' content-type if not specified.
|
|
117
117
|
* @param {string} content - The text content to return
|
|
118
118
|
* @param {ResponseInit} [init] - Additional response initialization options
|
|
119
119
|
* @returns {Response} A Response object with text/plain content-type
|
|
@@ -135,7 +135,7 @@ export declare const text: (content: string, init?: ResponseInit) => Response;
|
|
|
135
135
|
export declare const html: (content: string, init?: ResponseInit) => Response;
|
|
136
136
|
/**
|
|
137
137
|
* Creates a JSON Response.
|
|
138
|
-
* Defaults to status 200 and application/json content-type if not specified.
|
|
138
|
+
* Defaults to status 200 and 'application/json; charset=utf-8' content-type if not specified.
|
|
139
139
|
* Uses Response.json() internally which automatically serializes the body.
|
|
140
140
|
* @param {any} body - The data to serialize as JSON
|
|
141
141
|
* @param {ResponseInit} [init] - Additional response initialization options
|
|
@@ -193,17 +193,17 @@ export declare const usp: (usp?: URLSearchParams, init?: ResponseInit) => Respon
|
|
|
193
193
|
/**
|
|
194
194
|
* Creates a Response from various body types with automatic content-type detection.
|
|
195
195
|
* Supports strings, objects (JSON), Blobs, ArrayBuffers, FormData, URLSearchParams, and ReadableStreams.
|
|
196
|
-
* @param {BodyInit} [body] - The body content to return
|
|
196
|
+
* @param {BodyInit|Record<string, unknown>} [body] - The body content to return
|
|
197
197
|
* @param {ResponseInit} [init] - Additional response initialization options
|
|
198
198
|
* @returns {Response} A Response object with appropriate content-type
|
|
199
199
|
* @example
|
|
200
200
|
* send("text"); // text/plain
|
|
201
|
-
* send({ message: "success" }); // application/json
|
|
201
|
+
* send({ message: "success" }); // application/json; charset=utf-8
|
|
202
202
|
* send(new Blob([])); // blob.type || application/octet-stream
|
|
203
203
|
* send(new FormData()); // multipart/form-data
|
|
204
204
|
* send(new URLSearchParams()); // application/x-www-form-urlencoded
|
|
205
205
|
*/
|
|
206
|
-
export declare const send: (body?: BodyInit, init?: ResponseInit) => Response;
|
|
206
|
+
export declare const send: (body?: BodyInit | Record<string, unknown>, init?: ResponseInit) => Response;
|
|
207
207
|
/**
|
|
208
208
|
* Options for setting cookies.
|
|
209
209
|
* @typedef {Object} CookieOptions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAExD,cAAc,iBAAiB,CAAC;AAEhC,oBAAY,MAAM;IAChB,aAAa,MAAM;IACnB,uBAAuB,MAAM;IAC7B,eAAe,MAAM;IACrB,eAAe,MAAM;IACrB,OAAO,MAAM;IACb,YAAY,MAAM;IAClB,aAAa,MAAM;IACnB,gCAAgC,MAAM;IACtC,cAAc,MAAM;IACpB,iBAAiB,MAAM;IACvB,mBAAmB,MAAM;IACzB,gBAAgB,MAAM;IACtB,oBAAoB,MAAM;IAC1B,WAAW,MAAM;IACjB,oBAAoB,MAAM;IAC1B,qBAAqB,MAAM;IAC3B,UAAU,MAAM;IAChB,aAAa,MAAM;IACnB,gBAAgB,MAAM;IACtB,aAAa,MAAM;IACnB,sBAAsB,MAAM;IAC5B,sBAAsB,MAAM;IAC5B,eAAe,MAAM;IACrB,iBAAiB,MAAM;IACvB,oBAAoB,MAAM;IAC1B,cAAc,MAAM;IACpB,aAAa,MAAM;IACnB,qBAAqB,MAAM;IAC3B,kBAAkB,MAAM;IACxB,gCAAgC,MAAM;IACtC,mBAAmB,MAAM;IACzB,aAAa,MAAM;IACnB,SAAS,MAAM;IACf,mBAAmB,MAAM;IACzB,uBAAuB,MAAM;IAC7B,oBAAoB,MAAM;IAC1B,eAAe,MAAM;IACrB,yBAAyB,MAAM;IAC/B,wBAAwB,MAAM;IAC9B,sBAAsB,MAAM;IAC5B,cAAc,MAAM;IACpB,uBAAuB,MAAM;IAC7B,wBAAwB,MAAM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AO,GAAG,GAAG,EACb,QAAQ,SAAS,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,CACrD,cAAc,CAAC,OAAO,CAAC,CACxB,EAED,SAAS,OAAO,EAChB,GAAG,UAAU,CAAC,GAAG,QAAQ,CAAC,KACzB;IAAE,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAUrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,kBAAkB,GAC7B,OAAO,GAAG,GAAG,EACb,OAAO,SAAS,mBAAmB,CAAC,OAAO,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAAC,EAC3E,QAAQ,SAAS,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,CACrD,cAAc,CAAC,OAAO,CAAC,CACxB,EAED,SAAS,OAAO,EAChB,SAAS,OAAO,EAChB,GAAG,UAAU,CAAC,GAAG,QAAQ,CAAC,KACzB;IAAE,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAoBrC,CAAC"}
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -275,7 +275,7 @@ function getHttpStatusText(code) {
|
|
|
275
275
|
}
|
|
276
276
|
/**
|
|
277
277
|
* Creates a Response with the specified status code.
|
|
278
|
-
* Defaults to text/plain content-type if not provided in init.headers.
|
|
278
|
+
* Defaults to 'text/plain; charset=utf-8' content-type if not provided in init.headers.
|
|
279
279
|
* @param {number} status - The HTTP status code
|
|
280
280
|
* @param {string|null} [content] - The response body content
|
|
281
281
|
* @param {ResponseInit} [init] - Additional response initialization options
|
|
@@ -290,7 +290,7 @@ const status = (status, content, init) => {
|
|
|
290
290
|
const statusText = (_a = init === null || init === void 0 ? void 0 : init.statusText) !== null && _a !== void 0 ? _a : getHttpStatusText(status);
|
|
291
291
|
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
292
292
|
if (content !== null && !headers.has("content-type")) {
|
|
293
|
-
headers.set("content-type", "text/plain");
|
|
293
|
+
headers.set("content-type", "text/plain; charset=utf-8");
|
|
294
294
|
}
|
|
295
295
|
return new Response(content !== undefined ? content : statusText, Object.assign(Object.assign({ statusText }, init), { status,
|
|
296
296
|
headers }));
|
|
@@ -348,7 +348,7 @@ const forward = (path, options) => {
|
|
|
348
348
|
exports.forward = forward;
|
|
349
349
|
/**
|
|
350
350
|
* Creates a text/plain Response.
|
|
351
|
-
* Defaults to status 200 and text/plain content-type if not specified.
|
|
351
|
+
* Defaults to status 200 and 'text/plain; charset=utf-8' content-type if not specified.
|
|
352
352
|
* @param {string} content - The text content to return
|
|
353
353
|
* @param {ResponseInit} [init] - Additional response initialization options
|
|
354
354
|
* @returns {Response} A Response object with text/plain content-type
|
|
@@ -362,7 +362,7 @@ const text = (content, init) => {
|
|
|
362
362
|
const statusText = (_b = init === null || init === void 0 ? void 0 : init.statusText) !== null && _b !== void 0 ? _b : getHttpStatusText(status);
|
|
363
363
|
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
364
364
|
if (!headers.has("content-type")) {
|
|
365
|
-
headers.set("content-type", "text/plain");
|
|
365
|
+
headers.set("content-type", "text/plain; charset=utf-8");
|
|
366
366
|
}
|
|
367
367
|
return new Response(content, Object.assign(Object.assign({ statusText }, init), { status,
|
|
368
368
|
headers }));
|
|
@@ -384,7 +384,7 @@ const html = (content, init) => {
|
|
|
384
384
|
const statusText = (_b = init === null || init === void 0 ? void 0 : init.statusText) !== null && _b !== void 0 ? _b : getHttpStatusText(status);
|
|
385
385
|
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
386
386
|
if (!headers.has("content-type")) {
|
|
387
|
-
headers.set("content-type", "text/html");
|
|
387
|
+
headers.set("content-type", "text/html; charset=utf-8");
|
|
388
388
|
}
|
|
389
389
|
return new Response(content, Object.assign(Object.assign({ statusText }, init), { status,
|
|
390
390
|
headers }));
|
|
@@ -392,7 +392,7 @@ const html = (content, init) => {
|
|
|
392
392
|
exports.html = html;
|
|
393
393
|
/**
|
|
394
394
|
* Creates a JSON Response.
|
|
395
|
-
* Defaults to status 200 and application/json content-type if not specified.
|
|
395
|
+
* Defaults to status 200 and 'application/json; charset=utf-8' content-type if not specified.
|
|
396
396
|
* Uses Response.json() internally which automatically serializes the body.
|
|
397
397
|
* @param {any} body - The data to serialize as JSON
|
|
398
398
|
* @param {ResponseInit} [init] - Additional response initialization options
|
|
@@ -407,7 +407,7 @@ const json = (body, init) => {
|
|
|
407
407
|
const statusText = (_b = init === null || init === void 0 ? void 0 : init.statusText) !== null && _b !== void 0 ? _b : getHttpStatusText(status);
|
|
408
408
|
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
409
409
|
if (!headers.has("content-type")) {
|
|
410
|
-
headers.set("content-type", "application/json");
|
|
410
|
+
headers.set("content-type", "application/json; charset=utf-8");
|
|
411
411
|
}
|
|
412
412
|
return Response.json(body, Object.assign(Object.assign({ statusText }, init), { status,
|
|
413
413
|
headers }));
|
|
@@ -504,12 +504,12 @@ exports.usp = usp;
|
|
|
504
504
|
/**
|
|
505
505
|
* Creates a Response from various body types with automatic content-type detection.
|
|
506
506
|
* Supports strings, objects (JSON), Blobs, ArrayBuffers, FormData, URLSearchParams, and ReadableStreams.
|
|
507
|
-
* @param {BodyInit} [body] - The body content to return
|
|
507
|
+
* @param {BodyInit|Record<string, unknown>} [body] - The body content to return
|
|
508
508
|
* @param {ResponseInit} [init] - Additional response initialization options
|
|
509
509
|
* @returns {Response} A Response object with appropriate content-type
|
|
510
510
|
* @example
|
|
511
511
|
* send("text"); // text/plain
|
|
512
|
-
* send({ message: "success" }); // application/json
|
|
512
|
+
* send({ message: "success" }); // application/json; charset=utf-8
|
|
513
513
|
* send(new Blob([])); // blob.type || application/octet-stream
|
|
514
514
|
* send(new FormData()); // multipart/form-data
|
|
515
515
|
* send(new URLSearchParams()); // application/x-www-form-urlencoded
|
|
@@ -519,30 +519,38 @@ const send = (body, init) => {
|
|
|
519
519
|
const status = (_a = init === null || init === void 0 ? void 0 : init.status) !== null && _a !== void 0 ? _a : 200;
|
|
520
520
|
const statusText = (_b = init === null || init === void 0 ? void 0 : init.statusText) !== null && _b !== void 0 ? _b : getHttpStatusText(status);
|
|
521
521
|
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
522
|
-
|
|
523
|
-
|
|
522
|
+
const isContentTypeNotSet = !headers.has("content-type");
|
|
523
|
+
if (body instanceof URLSearchParams) {
|
|
524
|
+
if (isContentTypeNotSet) {
|
|
524
525
|
headers.set("content-type", "application/x-www-form-urlencoded");
|
|
525
|
-
body = body.toString();
|
|
526
526
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
527
|
+
}
|
|
528
|
+
else if (body instanceof FormData) {
|
|
529
|
+
// content type will be generated
|
|
530
|
+
}
|
|
531
|
+
else if (typeof body === "string") {
|
|
532
|
+
if (isContentTypeNotSet) {
|
|
530
533
|
headers.set("content-type", "text/plain; charset=utf-8");
|
|
531
534
|
}
|
|
532
|
-
|
|
535
|
+
}
|
|
536
|
+
else if (body instanceof Blob) {
|
|
537
|
+
if (isContentTypeNotSet) {
|
|
533
538
|
headers.set("content-type", body.type || "application/octet-stream");
|
|
534
539
|
}
|
|
535
|
-
|
|
540
|
+
}
|
|
541
|
+
else if (body instanceof ArrayBuffer ||
|
|
542
|
+
ArrayBuffer.isView(body) ||
|
|
543
|
+
body instanceof ReadableStream) {
|
|
544
|
+
if (isContentTypeNotSet) {
|
|
536
545
|
headers.set("content-type", "application/octet-stream");
|
|
537
546
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
}
|
|
543
|
-
else {
|
|
544
|
-
headers.set("content-type", "application/octet-stream");
|
|
547
|
+
}
|
|
548
|
+
else if (body != null) {
|
|
549
|
+
if (isContentTypeNotSet) {
|
|
550
|
+
headers.set("content-type", "application/json; charset=utf-8");
|
|
545
551
|
}
|
|
552
|
+
return Response.json(body, Object.assign(Object.assign({ status,
|
|
553
|
+
statusText }, init), { headers }));
|
|
546
554
|
}
|
|
547
555
|
return new Response(body, Object.assign(Object.assign({ statusText }, init), { status,
|
|
548
556
|
headers }));
|