T
TanStack4mo ago
fair-rose

Accessing request object in the Route.loader

I would like to get access to request headers in the loader to get the IP address (to display that the service is not available in certain countries). What is the proper way of getting access to the request object / headers in the loader? I have tried adding getHeader but that causes a build error.
"Readable" is not exported by "__vite-browser-external",
"Readable" is not exported by "__vite-browser-external",
2 Replies
fair-rose
fair-roseOP4mo ago
I ended up defining a server fn and calling the server fn in the loader.
metropolitan-bronze
metropolitan-bronze4mo ago
that's the way loaders are isomorphic, which means they run on both client and server hence if you need something to always run on the server, you need to wrap into a server function

Did you find this page helpful?