| 1 | import { redirectDocument, type MiddlewareFunction } from "react-router"; |
| 2 | import { needsBuildRefresh } from "./build-version"; |
| 3 | import { pageOf } from "./confirm-gate"; |
| 4 | |
| 5 | export const buildVersionMiddleware: MiddlewareFunction<Response> = async ({ request }, next) => { |
| 6 | if (needsBuildRefresh(request, import.meta.env.G1T_BUILD_ID)) { |
| 7 | const url = new URL(request.url); |
| 8 | url.searchParams.delete("_routes"); |
| 9 | throw redirectDocument(pageOf(url.pathname) + url.search, { headers: { "cache-control": "no-store" } }); |
| 10 | } |
| 11 | return next(); |
| 12 | }; |