bxo 0.0.5-dev.34 → 0.0.5-dev.35
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/index.ts +24 -9
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -88,6 +88,7 @@ export type Context<TConfig extends RouteConfig = {}> = {
|
|
|
88
88
|
? InferZodType<TConfig['response']>
|
|
89
89
|
: any;
|
|
90
90
|
redirect: (location: string, status?: number) => Response;
|
|
91
|
+
clearRedirect: () => void;
|
|
91
92
|
[key: string]: any;
|
|
92
93
|
};
|
|
93
94
|
|
|
@@ -601,16 +602,14 @@ export default class BXO {
|
|
|
601
602
|
return data;
|
|
602
603
|
}) as any,
|
|
603
604
|
redirect: ((location: string, status: number = 302) => {
|
|
604
|
-
//
|
|
605
|
-
ctx.set.status = status;
|
|
606
|
-
ctx.set.headers = {
|
|
607
|
-
...(ctx.set.headers || {}),
|
|
608
|
-
Location: location
|
|
609
|
-
};
|
|
605
|
+
// Record redirect intent only; avoid mutating generic status/headers so it can be canceled later
|
|
610
606
|
ctx.set.redirect = { location, status };
|
|
611
607
|
|
|
612
|
-
// Prepare headers for immediate Response return
|
|
613
|
-
const responseHeaders: Record<string, string> = {
|
|
608
|
+
// Prepare headers for immediate Response return without persisting to ctx.set.headers
|
|
609
|
+
const responseHeaders: Record<string, string> = {
|
|
610
|
+
Location: location,
|
|
611
|
+
...(ctx.set.headers || {})
|
|
612
|
+
};
|
|
614
613
|
|
|
615
614
|
// Handle cookies if any are set on context
|
|
616
615
|
if (ctx.set.cookies && ctx.set.cookies.length > 0) {
|
|
@@ -634,7 +633,23 @@ export default class BXO {
|
|
|
634
633
|
status,
|
|
635
634
|
headers: responseHeaders
|
|
636
635
|
});
|
|
637
|
-
}) as any
|
|
636
|
+
}) as any,
|
|
637
|
+
clearRedirect: (() => {
|
|
638
|
+
// Clear explicit redirect intent
|
|
639
|
+
delete ctx.set.redirect;
|
|
640
|
+
// Remove any Location header if present
|
|
641
|
+
if (ctx.set.headers) {
|
|
642
|
+
for (const key of Object.keys(ctx.set.headers)) {
|
|
643
|
+
if (key.toLowerCase() === 'location') {
|
|
644
|
+
delete ctx.set.headers[key];
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
// Reset status if it is a redirect
|
|
649
|
+
if (typeof ctx.set.status === 'number' && ctx.set.status >= 300 && ctx.set.status < 400) {
|
|
650
|
+
delete ctx.set.status;
|
|
651
|
+
}
|
|
652
|
+
}) as any
|
|
638
653
|
};
|
|
639
654
|
} catch (validationError) {
|
|
640
655
|
// Validation failed - return error response
|