@samitouri / QOSami-HFS / commits / 2a389e9f

handle a strange case

Massimo Melina committed Apr 19, 2025 at 15:17 UTC 2a389e9f6b1bce17174cccab992454047e03b756
1 file changed +5 -5
src/roots.ts
+5 -5
@@ -22,6 +22,8 @@ forceAddress.sub((v, { version }) => { // convert from legacy configs
22
23 export const rootsMiddleware: Koa.Middleware = (ctx, next) =>
24 (() => {
25 + if (!ctx.path) // it was once reported "Cannot read properties of null (reading 'startsWith')" but I can't reproduce it, and it shouldn't happen anyway
26 + return disconnect(ctx, 'no path') // let's assume that such requests can't be served anyway. This will leave a trace with an ip, anyway
27 ctx.state.originalPath = ctx.path
28 let params: undefined | typeof ctx.state.params | typeof ctx.query // undefined if we are not going to work on api parameters
29 if (ctx.path.startsWith(SPECIAL_URI)) { // special uris should be excluded...
@@ -33,11 +35,9 @@ export const rootsMiddleware: Koa.Middleware = (ctx, next) =>
35 }
36 if (_.isEmpty(roots.get())) return
37 const root = ctx.state.root = roots.compiled()?.(ctx.host)
36 - if (!ctx.state.skipFilters && forceAddress.get())
37 - if (root === undefined && !isLocalHost(ctx) && ctx.host !== baseUrl.compiled()) {
38 - disconnect(ctx, forceAddress.key())
39 - return true // true will avoid calling next
40 - }
38 + if (!ctx.state.skipFilters && forceAddress.get()
39 + && root === undefined && !isLocalHost(ctx) && ctx.host !== baseUrl.compiled())
40 + return disconnect(ctx, forceAddress.key()) // returning truthy will not call next
41 if (!root || root === '/') return // no transformation is required
42 changeUriParams(v => join(root, v))
43 if (!params)