Giter VIP home page Giter VIP logo

cf-workers-typescript-template's Introduction

Cloudflare Workers Typescript Server & Client Template

GitHub Actions Test GitHub Actions Deploy LGTM Alerts LGTM Code Quality Code Climate Maintainability Codecov License GitHub Last Commit Lerna

A perfect* template for a Cloudflare Workers project, using Workers Sites (React although can be easily swapped for Gatsby or another static builder), TypeScript, Jest and Prettier.

And now, with end-to-end tests thanks to the new wrangler dev command and Playwright! โœจ

Prerequisites

  • Node.js

  • cloudflared

    (On MacOS with Homebrew: brew install cloudflare/cloudflare/cloudflared)

Getting Started

Automatic

Click the button below and follow the setup instructions.

Deploy to Cloudflare Workers

Manual

  1. Fork repository:

    1. Click the Use this template button.

    2. Add GitHub Actions secret for CF_ACCOUNT_ID and CF_API_TOKEN using Edit Cloudflare Workers template permissions.

    3. Enable the CodeClimate, Codecov, LGTM, and Synk apps.

  2. (Optionally) Update .nvmrc:

    • Find available versions with nvm ls-remote
    • Use the current Node.js version with node -v > .nvmrc
  3. Update wrangler.toml:

    1. Replace script-name and script-name-dev with new-script-name and new-script-name-dev respectively.

    2. Add KV Namespaces. For example:

      kv-namespaces = [
        { binding = "NAMESPACENAME", id = "86bbce2f10524d33a5f26517e8dee123" }
      ]
      • Find existing namespaces with wrangler kv:namespace list
      • Create a new namespace with wrangler kv:namespace create NAMESPACENAME
    3. Update account_id.

  4. Update package.json:

    1. Replace script-name with new-script-name.

    2. Replace repositoryname with newrepositoryname.

    3. Update GitHub account name in the following locations:

      1. repository.url

      2. bugs.url

      3. homepage

    4. Update homepage and author.

  5. npm i

  6. (Optionally) Update npm packages: npm run updatePackages

  7. Update README.md, (don't forget the badges!).

  8. Follow additional instructions in /packages/*/README.md

Scripts

These should all be self-explanatory:

  • npm run lint

    • npm run lint:fix
  • npm run test

    • npm run test:client
    • npm run test:server
    • npm run test:e2e
  • npm run deploy

To start a local version:

  1. In one terminal window, run npm run start:client.

  2. In another, run npm run start and navigate to http://localhost:8787.

About

  • /packages/client is simply a CRA created with npx create-react-app . --template typescript --use-npm.

  • /packages/server an function which intercepts a request to the client. If it returns a 404, the request is passed through to the client.

  • /packages/worker attempts to fetch from the server first, falling back on the client.

  • /packages/e2e runs end-to-end tests on the full-stack Worker.


* May not be perfect

cf-workers-typescript-template's People

Contributors

dependabot[bot] avatar gregbrimble avatar snyk-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.