A Cloudflare Worker template that uses TypeScript and a custom route parser to give you better route control.
-
Click on Use this template.
-
Clone your repository.
-
Install dependencies:
pnpm install
-
Start the development server (this project is using Miniflare, a simulator for developing and testing Cloudflare Workers):
pnpm dev
-
Open development site:
http://localhost:8787
.
You need to fill out wrangler.toml
with your details (account_id
). Other options you can find here.
This repository is using Wrangler Action for deployment. You'll need to configure Wrangler using GitHub's encrypted secrets feature and add your Cloudflare API token. Action will deploy your application on pushes to the main
or master
branch.
Or you can run pnpm deploy
from your terminal.
Create a new file in the routes
directory and add a new route(s), e.g.:
router.addRoute({
path: new Route('/post'),
method: 'POST',
resolve: (req, res) => {
return res.send({ method: req.method, data: { hello: 'world' } });
}
});
Then import your new file into routes/index.ts
, and your route(s) will be automatically registered.
This project is licensed under the MIT license.