screfy / cf-worker-template

A Cloudflare Worker template that uses TypeScript and a custom route parser.

Home Page:https://cf-worker-template.screfy.workers.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cloudflare Worker Template

A Cloudflare Worker template that uses TypeScript and a custom route parser to give you better route control.

Setup

Prerequisites

Setting up a project

  1. Click on Use this template.

  2. Clone your repository.

  3. Install dependencies:

    pnpm install
  4. Start the development server (this project is using Miniflare, a simulator for developing and testing Cloudflare Workers):

    pnpm dev
  5. Open development site: http://localhost:8787.

Documentation

Configuration

You need to fill out wrangler.toml with your details (account_id). Other options you can find here.

Deployment

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.

Adding a new route

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.

License

This project is licensed under the MIT license.

About

A Cloudflare Worker template that uses TypeScript and a custom route parser.

https://cf-worker-template.screfy.workers.dev

License:MIT License


Languages

Language:TypeScript 85.9%Language:JavaScript 14.1%