523704b83f
* Do not exclude internal _next request in middleware * Allow for `NextURL` to parse prefetch requests * Add test for middleware data prefetch * Refactor `hasBasePath` and `replaceBasePath` * Refactor `removeTrailingSlash` * Refactor parsed next url to use `getNextPathnameInfo` * Allow to configure `NextURL` * Ensure middleware rewrites with always with a locale Co-authored-by: JJ Kasper <jj@jjsweb.site>
14 lines
528 B
TypeScript
14 lines
528 B
TypeScript
/**
|
|
* Takes an object with a hostname property (like a parsed URL) and some
|
|
* headers that may contain Host and returns the preferred hostname.
|
|
* @param parsed An object containing a hostname property.
|
|
* @param headers A dictionary with headers containing a `host`.
|
|
*/
|
|
export function getHostname(
|
|
parsed: { hostname?: string | null },
|
|
headers?: { [key: string]: string | string[] | undefined }
|
|
) {
|
|
return ((!Array.isArray(headers?.host) && headers?.host) || parsed.hostname)
|
|
?.split(':')[0]
|
|
.toLowerCase()
|
|
}
|