Skip to content

Commit

Permalink
fix(backend): Make createIsomorphicRequest return Request with url or…
Browse files Browse the repository at this point in the history
…igin generated by headers
  • Loading branch information
dimkl committed Sep 20, 2023
1 parent 559a0e6 commit 4d0d902
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shy-jeans-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': patch
---

Refactor the internal generation of request URLs to use a shared helper from `@clerk/backend`
6 changes: 5 additions & 1 deletion packages/backend/src/util/IsomorphicRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { parse } from 'cookie';

import runtime from '../runtime';
import { buildRequestUrl } from '../utils';

type IsomorphicRequestOptions = (Request: typeof runtime.Request, Headers: typeof runtime.Headers) => Request;
export const createIsomorphicRequest = (cb: IsomorphicRequestOptions): Request => {
return cb(runtime.Request, runtime.Headers);
const req = cb(runtime.Request, runtime.Headers);
// Used to fix request.url using the x-forwarded-* headers
const headersGeneratedURL = buildRequestUrl(req);
return new runtime.Request(headersGeneratedURL, req);
};

export const buildRequest = (req?: Request) => {
Expand Down

0 comments on commit 4d0d902

Please sign in to comment.