mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-24 06:25:48 +00:00
fix: move stats initialization into proxyservice
This commit is contained in:
parent
00f3a4dc0a
commit
fec6d4fa59
@ -27,6 +27,18 @@ export type ProxyMiddleware = (
|
||||
logger: Logger,
|
||||
) => boolean | Promise<boolean>
|
||||
|
||||
export type ProxyServiceConfig = SingletonBaseConfig & {
|
||||
coreInternalUrl: string
|
||||
}
|
||||
export const proxyService = mkSingleton(
|
||||
async (
|
||||
config: ProxyServiceConfig,
|
||||
): Promise<{ use: ReturnType<typeof express>['use'] }> => {
|
||||
const _proxyLogger = LoggerService().create('ProxyService')
|
||||
const { dbg, error, info, trace, warn } = _proxyLogger
|
||||
|
||||
const { coreInternalUrl } = config
|
||||
|
||||
const stats = (() => {
|
||||
const metrics = {
|
||||
requests: 0,
|
||||
@ -73,23 +85,14 @@ const stats = (() => {
|
||||
metrics.ips.set(ip, (metrics.ips.get(ip) || 0) + 1)
|
||||
},
|
||||
addCountry: (country: string) => {
|
||||
metrics.countries.set(country, (metrics.countries.get(country) || 0) + 1)
|
||||
metrics.countries.set(
|
||||
country,
|
||||
(metrics.countries.get(country) || 0) + 1,
|
||||
)
|
||||
},
|
||||
}
|
||||
})()
|
||||
|
||||
export type ProxyServiceConfig = SingletonBaseConfig & {
|
||||
coreInternalUrl: string
|
||||
}
|
||||
export const proxyService = mkSingleton(
|
||||
async (
|
||||
config: ProxyServiceConfig,
|
||||
): Promise<{ use: ReturnType<typeof express>['use'] }> => {
|
||||
const _proxyLogger = LoggerService().create('ProxyService')
|
||||
const { dbg, error, info, trace, warn } = _proxyLogger
|
||||
|
||||
const { coreInternalUrl } = config
|
||||
|
||||
const proxy = httpProxy.createProxyServer({})
|
||||
proxy.on('error', (err, req, res, target) => {
|
||||
warn(`Proxy error ${err} on ${req.url} (${req.headers.host})`)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user