fix: (beta) SSE requests had not country logged
Massimo Melina committed
Dec 24, 2023 at 12:06 UTC
b8caedd3cb04210cbf98bd21783ff8db75d79069
2 files changed
+3
-2
src/geo.ts
+2
-1
@@ -20,7 +20,8 @@ export const geoFilter: Middleware = async (ctx, next) => {
20
if (enabled.get() && !isLocalHost(ctx)) {
21
const { connection } = ctx.state
22
const country = connection.country ??= await ip2country(ctx.ip)
23
- updateConnection(connection, { country })
23
+ if (country)
24
+ updateConnection(connection, { country })
25
if (allow.get() !== null)
26
if (country ? list.get().includes(country) !== allow.get() : !allowUnknown.get())
27
return disconnect(ctx)
src/log.ts
+1
-1
@@ -71,6 +71,7 @@ export const logMw: Koa.Middleware = async (ctx, next) => {
71
const now = new Date()
72
await next()
73
console.debug(ctx.status, ctx.method, ctx.originalUrl)
74
+ const conn = getConnection(ctx) // collect reference before close
75
// don't await, as we don't want to hold the middlewares chain
76
ctx.state.completed = Promise.race([ once(ctx.res, 'finish'), once(ctx.res, 'close') ])
77
ctx.state.completed.then(() => {
@@ -108,7 +109,6 @@ export const logMw: Koa.Middleware = async (ctx, next) => {
109
const uri = ctx.originalUrl
110
ctx.logExtra(ctx.state.includesLastByte && ctx.vfsNode && ctx.res.finished && { dl: 1 }
111
|| ctx.state.uploadSize !== undefined && { size: ctx.state.uploadSize, ul: ctx.state.uploads })
111
- const conn = getConnection(ctx)
112
if (conn?.country)
113
ctx.logExtra({ country: conn.country })
114
if (logUA.get())