-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use x-forwarded-host header in preview urls
- Loading branch information
1 parent
cb5a4c8
commit 85e05b3
Showing
3 changed files
with
29 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isNonEmptyString } from "@acdh-oeaw/lib"; | ||
|
||
/** | ||
* @see https://github.com/Thinkmill/keystatic/issues/978#issuecomment-2005730530 | ||
* @see https://github.com/Thinkmill/keystatic/issues/1022 | ||
*/ | ||
export function rewriteUrl(request: Request): Request { | ||
const forwardedHost = request.headers.get("x-forwarded-host"); | ||
const forwardedProto = request.headers.get("x-forwarded-proto"); | ||
const forwardedPort = request.headers.get("x-forwarded-port"); | ||
|
||
if (isNonEmptyString(forwardedHost) && isNonEmptyString(forwardedProto)) { | ||
const url = new URL(request.url); | ||
|
||
url.hostname = forwardedHost; | ||
url.protocol = forwardedProto; | ||
url.port = forwardedPort ?? ""; | ||
|
||
return new Request(url, request); | ||
} | ||
|
||
return request; | ||
} |