@spirobel/mininext 0.3.8 → 0.4.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/url.d.ts +3 -1
- package/dist/url.js +12 -1
- package/package.json +1 -1
package/dist/url.d.ts
CHANGED
|
@@ -45,6 +45,8 @@ export declare class Mini<X = unknown> {
|
|
|
45
45
|
params: URLSearchParams;
|
|
46
46
|
form: Form;
|
|
47
47
|
requrl: Readonly<URL>;
|
|
48
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
|
|
49
|
+
redirect: (url: string | URL, status?: number) => void;
|
|
48
50
|
constructor(mini: Mini<unknown>, data: X);
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
@@ -77,7 +79,7 @@ export declare class url {
|
|
|
77
79
|
private static frontends;
|
|
78
80
|
private static svgs;
|
|
79
81
|
static svg(path: string, options?: ResponseInit): string | undefined;
|
|
80
|
-
static frontend(path: string, snippet?: HtmlHandler): HtmlString;
|
|
82
|
+
static frontend(path: string, snippet?: HtmlHandler | BasedHtml): HtmlString;
|
|
81
83
|
/**
|
|
82
84
|
* This is used by the frontend bundler in order to find all frontends and their corresponding script files.
|
|
83
85
|
*/
|
package/dist/url.js
CHANGED
|
@@ -21,6 +21,8 @@ export class Mini {
|
|
|
21
21
|
params;
|
|
22
22
|
form;
|
|
23
23
|
requrl;
|
|
24
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
|
|
25
|
+
redirect;
|
|
24
26
|
constructor(mini, data) {
|
|
25
27
|
Object.assign(this, mini);
|
|
26
28
|
this.html = (html);
|
|
@@ -315,7 +317,8 @@ export class url {
|
|
|
315
317
|
}
|
|
316
318
|
const handler = url.direct_handlers_html.get(reqPath);
|
|
317
319
|
if (handler) {
|
|
318
|
-
|
|
320
|
+
let redirectTarget = null;
|
|
321
|
+
let redirectStatus = undefined;
|
|
319
322
|
let handlerHead = undefined;
|
|
320
323
|
let handlerOptions = {
|
|
321
324
|
headers: {
|
|
@@ -340,6 +343,7 @@ export class url {
|
|
|
340
343
|
if (post && (urlencoded || multipart)) {
|
|
341
344
|
formData = await req.formData();
|
|
342
345
|
}
|
|
346
|
+
//this is the source of mini
|
|
343
347
|
const mini = new Mini({
|
|
344
348
|
requrl: miniurl,
|
|
345
349
|
data: undefined,
|
|
@@ -381,8 +385,15 @@ export class url {
|
|
|
381
385
|
options: (options) => {
|
|
382
386
|
handlerOptions = options;
|
|
383
387
|
},
|
|
388
|
+
redirect: (url, status) => {
|
|
389
|
+
redirectTarget = url;
|
|
390
|
+
redirectStatus = status;
|
|
391
|
+
},
|
|
384
392
|
}, undefined);
|
|
385
393
|
const unresolved = await handler(mini); //passing mini
|
|
394
|
+
if (redirectTarget) {
|
|
395
|
+
return Response.redirect(redirectTarget, redirectStatus);
|
|
396
|
+
}
|
|
386
397
|
return htmlResponder(mini, unresolved, handlerHead, handlerOptions);
|
|
387
398
|
}
|
|
388
399
|
}
|