feat(www): locale specific urls (#12508)
This commit is contained in:
parent
8069197329
commit
24cd84cda5
33 changed files with 279 additions and 134 deletions
|
|
@ -1,5 +1,16 @@
|
|||
import { createMiddleware } from "@solidjs/start/middleware"
|
||||
import { LOCALE_HEADER, cookie, fromPathname, strip } from "~/lib/language"
|
||||
|
||||
export default createMiddleware({
|
||||
onBeforeResponse() {},
|
||||
onRequest(event) {
|
||||
const url = new URL(event.request.url)
|
||||
const locale = fromPathname(url.pathname)
|
||||
if (!locale) return
|
||||
|
||||
event.request.headers.set(LOCALE_HEADER, locale)
|
||||
event.response.headers.append("set-cookie", cookie(locale))
|
||||
|
||||
url.pathname = strip(url.pathname)
|
||||
event.request = new Request(url, event.request)
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue