|
@@ -0,0 +1,115 @@
|
|
|
|
|
+import { useEffect, useState } from 'react'
|
|
|
|
|
+import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
|
|
|
+import { api } from '@/api/client'
|
|
|
|
|
+import { controlCls, FormRow, SaveButton } from '@/components/form'
|
|
|
|
|
+import { useToastStore } from '@/stores/toastStore'
|
|
|
|
|
+import { ApiError } from '@/types'
|
|
|
|
|
+import type { SettingsView } from '@/types'
|
|
|
|
|
+
|
|
|
|
|
+/// The deployment's OWN hostnames: the admin name and any global names.
|
|
|
|
|
+///
|
|
|
|
|
+/// This tab exists because the project hostnames panel pointed at it and it did
|
|
|
|
|
+/// not exist. The server has carried `admin_hostname` and `global_hostnames` in
|
|
|
|
|
+/// global settings since 0.19.0, and the UI modelled neither - so an operator
|
|
|
|
|
+/// could store a project hostname, be told it was inert, be told to fix that in
|
|
|
|
|
+/// global settings, and find nothing there.
|
|
|
|
|
+export default function DeploymentHostnamesTab() {
|
|
|
|
|
+ const push = useToastStore((s) => s.push)
|
|
|
|
|
+ const qc = useQueryClient()
|
|
|
|
|
+ const q = useQuery({ queryKey: ['settings'], queryFn: () => api.getSettings() })
|
|
|
|
|
+
|
|
|
|
|
+ const [admin, setAdmin] = useState('')
|
|
|
|
|
+ const [globals, setGlobals] = useState('')
|
|
|
|
|
+ const [saving, setSaving] = useState(false)
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ const d = q.data as SettingsView | undefined
|
|
|
|
|
+ if (!d) return
|
|
|
|
|
+ setAdmin(d.admin_hostname ?? '')
|
|
|
|
|
+ setGlobals((d.global_hostnames ?? []).join('\n'))
|
|
|
|
|
+ }, [q.data])
|
|
|
|
|
+
|
|
|
|
|
+ const list = globals.split('\n').map((x) => x.trim()).filter(Boolean)
|
|
|
|
|
+ const gatingOn = admin.trim().length > 0 || list.length > 0
|
|
|
|
|
+
|
|
|
|
|
+ const submit = async (e: React.FormEvent) => {
|
|
|
|
|
+ e.preventDefault()
|
|
|
|
|
+ setSaving(true)
|
|
|
|
|
+ try {
|
|
|
|
|
+ await api.updateSettings({ admin_hostname: admin.trim(), global_hostnames: list })
|
|
|
|
|
+ await qc.invalidateQueries({ queryKey: ['settings'] })
|
|
|
|
|
+ push('Deployment hostnames saved.', 'success')
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ push(err instanceof ApiError ? err.message : String(err), 'error')
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ setSaving(false)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (q.isLoading) return <p className="text-sm text-slate-400">Loading...</p>
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <form onSubmit={submit} className="flex flex-col gap-5">
|
|
|
|
|
+ {/* The consequence first. Setting either field changes behaviour for
|
|
|
|
|
+ EVERY request to this deployment, including the operator's own next
|
|
|
|
|
+ one, so it must not read as an ordinary text box. */}
|
|
|
|
|
+ <div
|
|
|
|
|
+ className={
|
|
|
|
|
+ gatingOn
|
|
|
|
|
+ ? 'rounded-md border border-emerald-500/30 bg-emerald-500/5 p-3'
|
|
|
|
|
+ : 'rounded-md border border-amber-500/30 bg-amber-500/5 p-3'
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
|
|
+ <p className="text-sm font-medium text-slate-100">
|
|
|
|
|
+ {gatingOn ? 'Host gating is in force.' : 'Host gating is OFF.'}
|
|
|
|
|
+ </p>
|
|
|
|
|
+ <p className="mt-1 text-xs text-slate-400">
|
|
|
|
|
+ {gatingOn
|
|
|
|
|
+ ? 'Every request carrying an unregistered Host answers 404, and each project hostname serves only its own project.'
|
|
|
|
|
+ : 'Every project hostname stored anywhere in this deployment is saved and INERT. Naming the deployment here is what turns gating on.'}
|
|
|
|
|
+ </p>
|
|
|
|
|
+ <p className="mt-2 text-xs text-slate-500">
|
|
|
|
|
+ A request arriving on the LOOPBACK interface is always treated as the admin surface, so
|
|
|
|
|
+ setting a name here is not a one-way door: you can always reach this service from the
|
|
|
|
|
+ machine itself to correct a mistake.
|
|
|
|
|
+ </p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <FormRow
|
|
|
|
|
+ label="Admin hostname"
|
|
|
|
|
+ hint="Serves everything: the API, functions, this web UI and /docs. Leave empty for none."
|
|
|
|
|
+ >
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ value={admin}
|
|
|
|
|
+ onChange={(e) => setAdmin(e.target.value)}
|
|
|
|
|
+ placeholder="admin.example.com"
|
|
|
|
|
+ className={`${controlCls} w-full max-w-lg font-mono`}
|
|
|
|
|
+ />
|
|
|
|
|
+ </FormRow>
|
|
|
|
|
+
|
|
|
|
|
+ <FormRow
|
|
|
|
|
+ label="Global hostnames"
|
|
|
|
|
+ hint="One per line. Serve every project's API with the project named in the path. No web UI, no /docs."
|
|
|
|
|
+ >
|
|
|
|
|
+ <textarea
|
|
|
|
|
+ value={globals}
|
|
|
|
|
+ onChange={(e) => setGlobals(e.target.value)}
|
|
|
|
|
+ rows={4}
|
|
|
|
|
+ placeholder={'api.example.com'}
|
|
|
|
|
+ className={`${controlCls} w-full max-w-lg font-mono`}
|
|
|
|
|
+ />
|
|
|
|
|
+ </FormRow>
|
|
|
|
|
+
|
|
|
|
|
+ <p className="text-xs text-slate-500">
|
|
|
|
|
+ A certificate is needed for each name before it can serve: a hostname without one gets a
|
|
|
|
|
+ refused TLS handshake rather than another hostname's certificate. Certificates are issued
|
|
|
|
|
+ by the reconciler on this host, not from this screen.
|
|
|
|
|
+ </p>
|
|
|
|
|
+
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <SaveButton saving={saving} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </form>
|
|
|
|
|
+ )
|
|
|
|
|
+}
|