/
githubmirror
/
gogs
Обзор
Документация
Войти
/
githubmirror
/
gogs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
web/src/lib/context.ts
26 строк
632 B
ᴊᴏᴇ ᴄʜᴇɴ
Embed WebContext and add /api/web/user-info endpoint (#8282)
21 май 2026, 21:43
Не верифицирован
21 май 2026, 21:43
90790b2
Код
Авторство
О чём код?
// WebContext mirrors the Go struct the server injects via // <script>window.__webContext = {...}</script> at the top of index.html. // Read it once at module load so callers get a stable snapshot. export interface WebContext { lang: string; subURL: string; } declare global { interface Window { __webContext?: Partial<WebContext>; } } function read(): WebContext { if (typeof window === "undefined") { return { lang: "en-US", subURL: "" }; } const ctx = window.__webContext ?? {}; return { lang: ctx.lang || "en-US", subURL: ctx.subURL ?? "", }; } export const webContext: WebContext = read();