mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-20 01:06:45 +00:00
[management, reverse proxy] Add reverse proxy feature (#5291)
* implement reverse proxy --------- Co-authored-by: Alisdair MacLeod <git@alisdairmacleod.co.uk> Co-authored-by: mlsmaycon <mlsmaycon@gmail.com> Co-authored-by: Eduard Gert <kontakt@eduardgert.de> Co-authored-by: Viktor Liu <viktor@netbird.io> Co-authored-by: Diego Noguês <diego.sure@gmail.com> Co-authored-by: Diego Noguês <49420+diegocn@users.noreply.github.com> Co-authored-by: Bethuel Mmbaga <bethuelmbaga12@gmail.com> Co-authored-by: Zoltan Papp <zoltan.pmail@gmail.com> Co-authored-by: Ashley Mensah <ashleyamo982@gmail.com>
This commit is contained in:
54
proxy/web/src/data.ts
Normal file
54
proxy/web/src/data.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
// Auth method types matching Go
|
||||
export type AuthMethod = 'pin' | 'password' | 'oidc' | "link"
|
||||
|
||||
// Page types
|
||||
export type PageType = 'auth' | 'error'
|
||||
|
||||
// Error data structure
|
||||
export interface ErrorData {
|
||||
code: number
|
||||
title: string
|
||||
message: string
|
||||
proxy?: boolean
|
||||
destination?: boolean
|
||||
requestId?: string
|
||||
simple?: boolean
|
||||
retryUrl?: string
|
||||
}
|
||||
|
||||
// Data injected by Go templates
|
||||
export interface Data {
|
||||
page?: PageType
|
||||
methods?: Partial<Record<AuthMethod, string>>
|
||||
error?: ErrorData
|
||||
}
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var __DATA__: Data | undefined
|
||||
}
|
||||
|
||||
export function getData(): Data {
|
||||
const data = globalThis.__DATA__ ?? {}
|
||||
|
||||
// Dev mode: allow ?page=error query param to preview error page
|
||||
if (import.meta.env.DEV) {
|
||||
const params = new URLSearchParams(globalThis.location.search)
|
||||
const page = params.get('page')
|
||||
if (page === 'error') {
|
||||
return {
|
||||
...data,
|
||||
page: 'error',
|
||||
error: data.error ?? {
|
||||
code: 503,
|
||||
title: 'Service Unavailable',
|
||||
message: 'The service you are trying to access is temporarily unavailable. Please try again later.',
|
||||
proxy: true,
|
||||
destination: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
Reference in New Issue
Block a user