Reputation: 911
How is it possible to use environment variables in remix when deploying to cloudflare pages? The documentation gives some examples for different hosting providers, but not for cloudflare pages. After assuming, that dotenv
is the way to go, I get the error SyntaxError: missing ) after argument list
after running npm run dev
which executes "dev:remix": "node -r dotenv/config node_modules/.bin/remix watch"
.
How is it possible to use environment variables with remix in a cloudflare pages context?
Upvotes: 3
Views: 2422
Reputation: 914
For local development, create the file .dev.vars
in the root directory and add your environment variables:
MY_SUPER_SECRET_TOKEN=12345
Best to also .gitignore
this file too so you don't accidentally commit something for hackers to find.
On Cloudflare, set the same environment variables in the page's control panel.
Then, in your route's LoaderFunction
or ActionFunction
, access the environment variables through the context:
export const action: ActionFunction = async ({ request, context }) => {
console.log(context.MY_SUPER_SECRET_TOKEN)
}
Upvotes: 1