chore: proxyService singleton

This commit is contained in:
Ben Allfree 2022-12-31 06:41:05 -08:00
parent 337c2818a7
commit fe7fab71ba
2 changed files with 7 additions and 7 deletions

View File

@ -5,7 +5,7 @@ import { createBackupService } from './services/BackupService'
import { ftpService } from './services/FtpService/FtpService'
import { instanceService } from './services/InstanceService'
import { pocketbase } from './services/PocketBaseService'
import { createProxyService } from './services/ProxyService'
import { proxyService } from './services/ProxyService'
import { rpcService } from './services/RpcService'
logger({ debug: DEBUG })
@ -37,7 +37,7 @@ global.EventSource = require('eventsource')
ftpService({})
await rpcService({})
await instanceService({})
const proxyService = await createProxyService({
await proxyService({
coreInternalUrl: url,
})
const backupService = await createBackupService()
@ -48,7 +48,7 @@ global.EventSource = require('eventsource')
info(`Got signal ${signal}`)
info(`Shutting down`)
ftpService().shutdown()
proxyService.shutdown()
;(await proxyService()).shutdown()
;(await instanceService()).shutdown()
;(await rpcService()).shutdown()
pbService.shutdown()

View File

@ -1,4 +1,4 @@
import { logger } from '@pockethost/common'
import { logger, mkSingleton } from '@pockethost/common'
import { createServer } from 'http'
import httpProxy from 'http-proxy'
import { AsyncReturnType } from 'type-fest'
@ -9,12 +9,12 @@ import {
} from '../constants'
import { instanceService } from './InstanceService'
export type ProxyServiceApi = AsyncReturnType<typeof createProxyService>
export type ProxyServiceApi = AsyncReturnType<typeof proxyService>
export type ProxyServiceConfig = {
coreInternalUrl: string
}
export const createProxyService = async (config: ProxyServiceConfig) => {
export const proxyService = mkSingleton(async (config: ProxyServiceConfig) => {
const { dbg, error, info } = logger().create('ProxyService')
const { coreInternalUrl } = config
@ -89,4 +89,4 @@ export const createProxyService = async (config: ProxyServiceConfig) => {
}
return { shutdown }
}
})