stripe-node
Cloudflare Worker Template
This is a template for setting up a Cloudflare Worker which uses stripe-node
. The wrangler
CLI tool is used for publishing.
Generating
To generate using wrangler
wrangler generate projectname https://github.com/stripe-samples/stripe-node-cloudflare-worker-template
Further documentation for Wrangler can be found here.
Publishing
You can build and publish your worker using:
STRIPE_API_KEY="<YOUR API KEY HERE>" wrangler publish
This will build your application using Webpack and publish it. If this is your first time publishing, it will create a new worker named my-stripe-worker
under your account. If all goes well, the command will output a URL that looks something like https://my-stripe-worker.<your user name>.workers.dev
where your worker is available.
Alternatively, you can specify STRIPE_API_KEY
as an environment variable and use:
wrangler publish
Cloudflare Secrets
Cloudflare Workers offer a secrets infrastructure for storing an encrypted secret. You can use this instead of relying on an environment variable.
- Publish your worker at least once using the above instructions to bootstrap the worker.
- Remove the
DefinePlugin
fromwebpack.config.js
. - Run
wrangler secret put STRIPE_API_KEY
. This will prompt you to enter your secret (ie. your Stripe API key).
This only needs to be done the first time you are configuring up your new worker. It will persist across deployments. Once set up, you can publish using:
wrangler publish