mirror of
https://github.com/pockethost/pockethost.git
synced 2025-03-30 15:08:30 +00:00
35 lines
933 B
TypeScript
35 lines
933 B
TypeScript
import { PUBLIC_APP_DB } from '$constants'
|
|
import { mkSingleton, SingletonBaseConfig } from '@pockethost/common'
|
|
import { proxyService } from './ProxyService'
|
|
|
|
export type CentralDbServiceConfig = SingletonBaseConfig
|
|
|
|
export const centralDbService = mkSingleton(
|
|
async (config: CentralDbServiceConfig) => {
|
|
const { logger } = config
|
|
const { dbg } = logger.create(`centralDbService`)
|
|
|
|
;(await proxyService()).use(
|
|
PUBLIC_APP_DB,
|
|
['/api(/*)', '/_(/*)', '/'],
|
|
(req, res, meta, logger) => {
|
|
const { dbg } = logger
|
|
const { subdomain, coreInternalUrl, proxy } = meta
|
|
|
|
if (subdomain !== PUBLIC_APP_DB) return
|
|
|
|
const target = coreInternalUrl
|
|
dbg(
|
|
`Forwarding proxy request for ${req.url} to central instance ${target}`,
|
|
)
|
|
proxy.web(req, res, { target })
|
|
},
|
|
`CentralDbService`,
|
|
)
|
|
|
|
return {
|
|
shutdown() {},
|
|
}
|
|
},
|
|
)
|