All Projects → udacity → Cloudflare Typescript Workers

udacity / Cloudflare Typescript Workers

Licence: apache-2.0
Types and mocks for building a tested Typescript Cloudflare Worker, generates three NPM packages

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Cloudflare Typescript Workers

React Starter Kit
React Starter Kit — front-end starter kit using React, Relay, GraphQL, and JAM stack architecture
Stars: ✭ 21,060 (+22304.26%)
Mutual labels:  webpack, cdn, cloudflare
Sites Using Cloudflare
💔 Archived list of domains using Cloudflare DNS at the time of the CloudBleed announcement.
Stars: ✭ 1,914 (+1936.17%)
Mutual labels:  cloudflare, cdn
Cloudflare Workers Webpack Boilerplate
A superbly simple, minimal-config template for building, bundling and deploying Cloudflare Workers with Webpack 🚀
Stars: ✭ 101 (+7.45%)
Mutual labels:  webpack, cloudflare
php-proxy
php proxy based on GoAgent protocal,Implemented by golang
Stars: ✭ 85 (-9.57%)
Mutual labels:  cdn, cloudflare
Packages
📦 Package configurations - The #1 free and open source CDN built to make life easier for developers.
Stars: ✭ 139 (+47.87%)
Mutual labels:  cloudflare, cdn
CloudflareSpeedTest
🌩「自选优选 IP」测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4 / IPv6)!另外也支持其他 CDN / 网站 IP ~
Stars: ✭ 5,092 (+5317.02%)
Mutual labels:  cdn, cloudflare
detect-cloudflare-plus
True Sight Firefox extension.
Stars: ✭ 34 (-63.83%)
Mutual labels:  cdn, cloudflare
Fly
Deploy app servers close to your users. Package your app as a Docker image, and launch it in 17 cities with one simple CLI.
Stars: ✭ 862 (+817.02%)
Mutual labels:  cdn, edge-computing
Webpack Cdn Plugin
A webpack plugin that use externals of CDN urls for production and local node_modules for development
Stars: ✭ 306 (+225.53%)
Mutual labels:  webpack, cdn
Dynamic Cdn Webpack Plugin
Get your dependencies from a cdn rather than bundling them in your app
Stars: ✭ 312 (+231.91%)
Mutual labels:  webpack, cdn
Cloudflare Workers Webpack Plugin
Launch Cloudflare Workers to the Edge from the comfort of your build step 🚀
Stars: ✭ 18 (-80.85%)
Mutual labels:  webpack, cloudflare
Cloudflare Cname Setup
Cloudflare Partner Panel
Stars: ✭ 1,169 (+1143.62%)
Mutual labels:  cloudflare, cdn
Angular Webpack Starter
🌟 Angular Webpack Starter with AoT compilation, Lazy-loading, Tree-shaking, and Hot Module Reload (Updated to 4.1.0!)
Stars: ✭ 91 (-3.19%)
Mutual labels:  webpack
React Antd Admin
用React和Ant Design搭建的一个通用管理后台
Stars: ✭ 1,313 (+1296.81%)
Mutual labels:  webpack
Epub Manga Creator
a web GUI for create japanese epub manga
Stars: ✭ 90 (-4.26%)
Mutual labels:  webpack
Webpack Concat Plugin
a plugin to help webpack to concat file and inject to html
Stars: ✭ 91 (-3.19%)
Mutual labels:  webpack
Webpack Conditional Loader
C conditionals directive for JavaScript
Stars: ✭ 93 (-1.06%)
Mutual labels:  webpack
Django Project Template
Thorgate's Django project template - Django, React, Sass, optional Docker and more
Stars: ✭ 91 (-3.19%)
Mutual labels:  webpack
Libgdl
一个移动端跨平台的gpu+cpu并行计算的cnn框架(A mobile-side cross-platform gpu+cpu parallel computing CNN framework)
Stars: ✭ 91 (-3.19%)
Mutual labels:  edge-computing
Cdnjs
🤖 CDN assets - The #1 free and open source CDN built to make life easier for developers.
Stars: ✭ 9,270 (+9761.7%)
Mutual labels:  cdn

Cloudflare Workers with TypeScript and Webpack

CircleCI

Cloudflare Workers allow you to run JavaScript on Cloudflare's edge servers around the world. You can modify your site’s HTTP requests and responses, make parallel requests, or generate responses from the edge. This project develops, tests, and deploys NPM packages supporting the development of Cloudflare Workers using TypeScript.

Get started on your own TypeScript Cloudflare Worker using the Template.

  • types-cloudflare-worker - Complete types for all public features provided by Cloudflare Workers. Supports the Request.cf object, the Cache API and KV API.
  • cloudflare-worker-mock - Wraps service-worker-mock for name consistency, developer experience and to provide a simple mockable Cache API and KV API implementation.
  • @udacity/types-service-worker-mock - Incomplete types for the pinterest/service-worker-mock to support Cloudflare Worker Testing. May be pushed to the NPM @types project in the future, but needs additional work before that is reasonable.

The Cloudflare Worker API implements a subset of the Service Worker API specification, therefore Service Worker TypeScript types are a useful starting point.

Example

A small example of a strictly typed worker:

import CloudflareWorkerGlobalScope from 'types-cloudflare-worker';
declare var self: CloudflareWorkerGlobalScope;

export class Worker {
  public async handle(event: FetchEvent) {
    const originResponse = fetch(event.request, {
      cf: {
        minify: {
          html: true,
        },
      },
    });

    return originResponse;
  }
}

self.addEventListener('fetch', (event: FetchEvent) => {
  const worker = new Worker();
  event.respondWith(worker.handle(event));
});

Getting started

Start with the Starter Template or run the following commands:

npm init
# Add TypeScript
npm i -D \
  typescript \
  @types/node
# Setup the Cloudflare Worker Types and Mock
npm i -D \
  @udacity/types-service-worker-mock \
  types-cloudflare-worker \
  cloudflare-worker-mock

# Init TypeScript
tsc --init

Set the TypeScript compiler options in tsconfig.json:

"compilerOptions": {
  /* https://developers.cloudflare.com/workers/reference/ */
  /* Cloudflare Workers use the V8 JavaScript engine from Google Chrome. The
    * Workers runtime is updated at least once a week, to at least the version
    * that is currently used by Chrome’s stable release. This means you can
    * safely use latest JavaScript features, with no need for "transpilers".
    */
  "target": "ESNext",
  /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
  "module": "commonjs",
  /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
  "lib": ["esnext", "webworker"],
  /* Specify library files to be included in the compilation. */

  /* Recommend enabling all Strict Type-Checking Options and Additional Checks */
}

Building the Worker(s)

There are two implementations of the same test worker in this repository.

demo/src/helloworker.ts

This is the demo worker. It uses the published packages. Reference it as an example implementation and starting point for your project.

cd demo
npm i
jest
npm run build

src/helloworker.ts

This is the development worker. It uses the local packages.

npm i
jest
npm run build

Testing and deploying the packages

npm i
npm run test-all
scripts/publish.sh $VERSION $OTP # New version and 2FA

Author

Brad Erickson (@13rac1)

License

Licensed under the Apache License, Version 2.0.

© 2019 Udacity, Inc.

Content derived from Cloudflare Developer Documentation. © 2019 Cloudflare, Inc.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].