how to pass a process.env value from SSR context to client?
I have a .env variable for my API (let's say
process.env.SERVER_API
) and I want to make it available in my client. one way I thought to do this was context
so my file route components could access it as:
my implementation was:
the problem is, in ssr.rsx process.env.SERVER_API
resolves to a value but in the client process.env.SERVER_API
is undefined.
is there a way to accomplish what I'm trying to do here without adding the VITE_
prefix? I would prefer to use one env variable and not duplicate it for the client1 Reply
correct-apricot•7mo ago
unless you do some substitution of process.env on the client it won't be set
you could add the value to the router context by returning it from the root's beforeLoad