Skip to content

Commit 4ac925a

Browse files
committed
support rewrite for URL objects
1 parent 9c5b4b8 commit 4ac925a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/qwik-city/src/middleware/request-handler/request-event.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ export function createRequestEvent(
229229
return new RedirectMessage();
230230
},
231231

232-
rewrite: (_url: string) => {
232+
rewrite: (__url: string | URL) => {
233233
check();
234+
235+
const _url = typeof __url === 'string' ? __url : __url.toString();
234236
const fixedURL = _url.replace(/([^:])\/{2,}/g, '$1/');
235237
if (_url !== fixedURL) {
236238
console.warn(`Rewrite URL ${_url} is invalid, fixing to ${fixedURL}`);

packages/qwik-city/src/middleware/request-handler/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export interface RequestEventCommon<PLATFORM = QwikCityPlatform>
207207
* URL to rewrite to. When called, the response will immediately end with the correct rewrite url.
208208
* URL will remain unchanged in the browser history.
209209
*/
210-
readonly rewrite: (url: string) => RewriteMessage;
210+
readonly rewrite: (url: string | URL) => RewriteMessage;
211211

212212
/**
213213
* When called, the response will immediately end with the given status code. This could be useful

0 commit comments

Comments
 (0)