This is a development setup with docker compose for the Cloudflare OpenAPI Template.
Tip
While this example shows the Chanfana OpenAPI template, the principles on how to use Docker Compose can be applied for any other template as well.
-
Copy
.env.exampleto.envand.env.dev.exampleto.env.dev.task init
Note
- The
.env.devfile is used for development purposes, and can include variables/secrets likeCLOUDFLARE_API_TOKEN, and will not be parsed for wrangler types. - The
.envfile is used for production purposes, and can include variables/secrets likeAPI_KEY, that can be used for the application and will be parsed for wrangler types.
Important
By default, the API_KEY is set to your-api-key from the copied .env.example, along with the APP_ENV=development environment variable. Make sure to add/update the API_KEY secret and APP_ENV variable to the worker when deploying to CloudFlare.
-
Install dependencies before starting the container.
task npm:install
-
Start the container.
task up
-
Access the UI at
http://localhost:8788.
π TLDR
Initialize the project, install dependencies, and start the container.
task setupInstall NPM dependencies.
task npm:installUpdate NPM dependencies.
task npm:updateStart vite dev server.
task upStop and remove the container.
task downView container logs.
task logsGenerate wrangler types.
task wrangler:typesDeploy to Cloudflare Workers.
task wrangler:deployImportant
This requires the CLOUDFLARE_API_TOKEN to be set in the .env file.
Note
This will automatically set the APP_ENV variable to production.
Upload secret.
task wrangler:secret s=<NAME_OF_SECRET>
# Example
task wrangler:secret s=API_KEYImportant
- This requires the
CLOUDFLARE_API_TOKENto be set in the.envfile. - You will be prompted to enter the secret value.
Run biome format with safe fixes.
task biome:format:fixRun biome lint with safe fixes.
task biome:lint:fixRun biome check with safe fixes.
task biome:check:fix- The current development setup uses Vite with the
@cloudflare/vite-plugin.- You can also run the setup with just Wrangler (without Vite), but make sure you pass
--ip 0.0.0.0to thewrangler devcommand.If you usewrangler dev --ip 0.0.0.0
--hostinstead of--ip, you will get an empty response when trying to acces the page!
- You can also run the setup with just Wrangler (without Vite), but make sure you pass
- The base image for the docker compose worker service is
node:24-slim. - There is a Github action that releases a new version of the worker when pushed to
main(or manual workflow dispatch).- The action uses
cloudflare/wrangler-action@v3but has thewranglerVersionexplicitly set to match the version in thepackage.json(v4). - By default, the
release.ymlhasWRANGLER_QUIETset totrueandSHOW_DEPLOYMENT_URLset tofalse, which will hide the deployment URL from the logs.
- The action uses
- This Chanfana OpenAPI example uses middleware applied to all routes (for fast setup of secure API endpoints).
- Use the
x-api-keyheader to authenticate requests, or use the "Authorize" button when using the UI withAPI_KEYvalue set in the.envfile.
- Use the
- βοΈ Pre-commit.
- π Task (optional)
Run pre-commit install or task precommit:install to install the pre-commit hooks.
You are now ready to contribute!
This repository comes with a MIT license.