mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 03:00:45 +08:00
Fix duplicate /uds-auth route: drop rpc.handle, register webServer prefix once.
This commit is contained in:
parent
6caafe9590
commit
74ea52667d
1 changed files with 9 additions and 32 deletions
|
|
@ -33,7 +33,7 @@ function registerWebRoute(ctx) {
|
||||||
ctx.logger?.info?.('[uds-auth] Route registered: prefix /uds-auth')
|
ctx.logger?.info?.('[uds-auth] Route registered: prefix /uds-auth')
|
||||||
return () => dispose?.()
|
return () => dispose?.()
|
||||||
}
|
}
|
||||||
const present = tryGet(ctx, 'webServer')
|
const present = tryGet(ctx, 'webServer') ?? ctx.webServer
|
||||||
if (present !== undefined) return register(present)
|
if (present !== undefined) return register(present)
|
||||||
const disposers = []
|
const disposers = []
|
||||||
let registered = false
|
let registered = false
|
||||||
|
|
@ -684,10 +684,10 @@ function installSettingsSection(ctx, entry, hooks) {
|
||||||
export async function apply(ctx, config = {}) {
|
export async function apply(ctx, config = {}) {
|
||||||
let source = () => mergeConfig(config)
|
let source = () => mergeConfig(config)
|
||||||
_currentConfig = source()
|
_currentConfig = source()
|
||||||
|
_logger = ctx.logger || console
|
||||||
|
|
||||||
ctx.logger?.info?.('[uds-auth] Loading...')
|
ctx.logger?.info?.('[uds-auth] Loading...')
|
||||||
|
|
||||||
// Settings 注册 + RPC 注册:不依赖 webServer
|
|
||||||
installSettingsSection(ctx, source(), {
|
installSettingsSection(ctx, source(), {
|
||||||
setSource: (current) => {
|
setSource: (current) => {
|
||||||
source = typeof current === 'function' ? current : () => current
|
source = typeof current === 'function' ? current : () => current
|
||||||
|
|
@ -699,37 +699,14 @@ export async function apply(ctx, config = {}) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx.inject(['connection'], (connCtx) => {
|
// Do NOT rpc.handle('/uds-auth') — same path as webServer prefix → duplicate route / 415.
|
||||||
const rpc = connCtx.connection?.rpc
|
// Client uses HTTP /uds-auth/config.get instead.
|
||||||
if (!rpc || typeof rpc.handle !== 'function') {
|
|
||||||
ctx.logger?.warn?.('[uds-auth] connection.rpc.handle unavailable — client config UI disabled')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
connCtx.effect(() => {
|
|
||||||
const dispose = rpc.handle(UDS_AUTH_RPC_CHANNEL, async (endpoint) => {
|
|
||||||
if (endpoint === 'config.get') {
|
|
||||||
const c = source()
|
|
||||||
return {
|
|
||||||
ok: true,
|
|
||||||
value: {
|
|
||||||
uacBaseUrl: c.uacBaseUrl,
|
|
||||||
userSearchUrl: c.userSearchUrl,
|
|
||||||
loginSystemCode: c.loginSystemCode,
|
|
||||||
originSystemCode: c.originSystemCode,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { ok: false, error: 'unknown_endpoint' }
|
|
||||||
})
|
|
||||||
return () => dispose?.()
|
|
||||||
}, 'uds-auth: rpc')
|
|
||||||
})
|
|
||||||
|
|
||||||
// 初始化内部服务(session store, roles, auth middleware 等)
|
|
||||||
await initServices(ctx, source())
|
await initServices(ctx, source())
|
||||||
|
|
||||||
// 注册 webServer 路由(可能 webServer 已就绪,也可能需要等待)
|
// Register prefix once; wrap in effect so reload disposes cleanly.
|
||||||
registerWebRoute(ctx)
|
ctx.inject(['webServer'], (wctx) => {
|
||||||
|
wctx.effect(() => registerWebRoute(wctx), 'uds-auth: web route')
|
||||||
|
})
|
||||||
|
|
||||||
ctx.logger?.info?.('[uds-auth] Host ready')
|
ctx.logger?.info?.('[uds-auth] Host ready')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue