Created
May 2, 2023 19:02
-
-
Save AlexandroMtzG/9d18368cb4416d4252bcb4111a848dee to your computer and use it in GitHub Desktop.
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
import { HeadersFunction } from "@remix-run/node" | |
export const serverTimingHeaders: HeadersFunction = ({ | |
loaderHeaders, | |
parentHeaders, | |
}) => { | |
return setServerTimingHeaders(new Headers(), { | |
loaderHeaders, | |
parentHeaders, | |
}) | |
} | |
export function setServerTimingHeaders( | |
headers: Headers, | |
args: { | |
loaderHeaders: Headers | |
parentHeaders: Headers | |
}, | |
) { | |
if (args.loaderHeaders.has("Server-Timing")) { | |
headers.set( | |
"Server-Timing", | |
args.loaderHeaders.get("Server-Timing")!, | |
) | |
} | |
if (args.parentHeaders.has("Server-Timing")) { | |
headers.append( | |
"Server-Timing", | |
args.parentHeaders.get("Server-Timing")!, | |
) | |
} | |
return headers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment