Possible to hook into dev server? #3539
-
I have a Remix application which runs on AWS Lambda using a custom server entrypoint. But when developing I make use of the built in dev server. In my custom server file I extract an authorisation token from a cookie and use this to initialise Axios so that all requests made by Axios have an authorisation bearer header. I need to be able to do the same when running the dev server too. Is there any way to hook into the lifecycle of the dev server so that I can initialise Axios before the request is processed? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you use the Remix App Server ( Also, is the Axios instance a new one per request? Remember if you have a shared instance of Axios and you set the auth token there, if your server receives more than once request it may have race conditions where the token of the second user is used to fetch data as the first user. |
Beta Was this translation helpful? Give feedback.
If you use the Remix App Server (
remix dev
) there's no way to customize the code, you'll need to change to the Express setup, you can usenpx rmx eject-ras
to get the Express setup (see https://github.com/kiliman/rmx-cli).Also, is the Axios instance a new one per request? Remember if you have a shared instance of Axios and you set the auth token there, if your server receives more than once request it may have race conditions where the token of the second user is used to fetch data as the first user.