Gacha game centered around vore.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
vore-gacha/src/FastifyHelpers.ts

19 lines
868 B

/** Constructs the base URL from the headers from the given request. */
import {FastifyRequest} from "fastify";
import {RouteGenericInterface} from "fastify/types/route";
export interface RouteWithQuerystring extends RouteGenericInterface {
Querystring: {[key: string]: string|string[]|undefined}
}
export function getBaseUrl(request: FastifyRequest): string {
const hostHeader = request.hostname ?? "localhost"
const proto = getFirstValue(request.headers["x-forwarded-proto"]) ?? "http"
const path = getFirstValue(request.headers["x-base-path"]) ?? "/"
return `${proto}://${hostHeader}${path}`
}
/** Translates a zero-to-many set of strings to one or zero strings. */
export function getFirstValue(value: string|string[]|undefined): string|undefined {
return typeof value === "string" ? value : Array.isArray(value) ? value[0] : undefined
}