Skip to content

Instantly share code, notes, and snippets.

@yushanwebdev
Last active December 6, 2023 21:28
Show Gist options
  • Save yushanwebdev/4513da94a4c24978678dd7708afcd111 to your computer and use it in GitHub Desktop.
Save yushanwebdev/4513da94a4c24978678dd7708afcd111 to your computer and use it in GitHub Desktop.
An alternative mechanism for making available the env variables in the client (Inspired by Kent's suggestion in the custom scripts lesson of the EpicWeb.dev)
import { getEnv } from '#app/utils/env.server.ts'
export async function loader() {
const envData = JSON.stringify(getEnv())
const jsContent = `window.ENV = ${envData};`
return new Response(jsContent, {
headers: {
'Content-Type': 'application/javascript',
},
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment