-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathresource.locales.ts
More file actions
32 lines (25 loc) · 933 Bytes
/
resource.locales.ts
File metadata and controls
32 lines (25 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { cacheHeader } from "pretty-cache-header"
import { z } from "zod/v4"
import { type Language, type Namespace, resources } from "~/localization/resource"
import type { Route } from "./+types/resource.locales"
export async function loader({ request, context }: Route.LoaderArgs) {
const { isProductionDeployment } = context
const url = new URL(request.url)
const lng = z.enum(Object.keys(resources) as Language[]).parse(url.searchParams.get("lng"))
const namespaces = resources[lng]
const ns = z.enum(Object.keys(resources[lng]) as Namespace[]).parse(url.searchParams.get("ns"))
const headers = new Headers()
// On production, we want to add cache headers to the response
if (isProductionDeployment) {
headers.set(
"Cache-Control",
cacheHeader({
maxAge: "5m",
sMaxage: "1d",
staleWhileRevalidate: "7d",
staleIfError: "7d",
})
)
}
return Response.json(namespaces[ns], { headers })
}