fix: export type BuildParams

This commit is contained in:
Andras Bacsai committed 2022-11-21 14:07:11 +01:00
1 parent c9ebf4c01a
commit 07e81efeef
1 file changed
+21 -6
@@ -2,6 +2,27 @@
// "Build" means user generated content — what user builds.
export type BuildMode = "edit" | "preview" | "published";
export type BuildParams =
| {
projectId: string;
mode: BuildMode;
pathname: string;
pageId?: string;
}
| {
projectDomain: string;
mode: BuildMode;
pathname: string;
pageId?: string;
}
| undefined;
// A subtype of Request. To make testing easier.
type MinimalRequest = {
url: string;
headers: { get: (name: string) => string | null };
};
const modes = ["edit", "preview", "published"] as BuildMode[];
const getMode = (url: URL): BuildMode => {
const modeParam = url.searchParams.get("mode");
@@ -13,12 +34,6 @@ const getMode = (url: URL): BuildMode => {
return mode;
};
// A subtype of Request. To make testing easier.
type MinimalRequest = {
url: string;
headers: { get: (name: string) => string | null };
};
const getRequestHost = (request: MinimalRequest): string =>
request.headers.get("x-forwarded-host") || request.headers.get("host") || "";