Skip to main content

Cloudflare Workers

this module generated by :

esbuild mod.ts --bundle --platform=node --outfile=cf_workers/index.js --target=node10.4

Usage With Wrangler#

Install Wrangler#

npm install @cloudflare/wrangler -g

Generate App and cd app_name#

wrangler generate app_namecd app_name

Install nhttp-workers#

npm install nhttp-workers --save

Webpack#

Modify wrangler.toml

name = "app_name"type = "webpack"
account_id = "your_account_id"workers_dev = trueroute = ""zone_id = ""

Code#

Modify index.js

import { NHttp } from "nhttp-workers";
const app = new NHttp();
app.get("/hello", ({ response }) => {  return response.send("hello");});
// directlyapp.get("/hello2", () => {  return "hello";});
// fetchaddEventListener("fetch", (event) => {    event.respondWith(app.handleEvent(event));});

Run Development#

wrangler dev

More info https://developers.cloudflare.com/workers/