DEV Community

K.Banyawat
K.Banyawat

Posted on

AdonisJs 4 - Context per request problem for multi-tenant usage

My API uses AdonisJS 4.1 and also got requests from several domain (multi-tenant origin e.g. a.com, b.com either send request to the same API endpoint). I found that the origin header in middleware and controller is not the same as expected once API got concurrent request

Middleware

class DetectOrigin {
   async handle(context, next) {
     // middleware shows the correct origin
     console.log(context.request.header('origin'))
     next()
   }
}
Enter fullscreen mode Exit fullscreen mode

Controller

class SomeController {
  async index(context) {
    // controller shows the last request of an incoming concurrent request group
    console.log(context.request.header('origin'))
    context.response.send('Some response data')
  }
}
Enter fullscreen mode Exit fullscreen mode

Seem like context has been overwritten once another request comes. Anyone has any suggestion please help

Top comments (0)