Cloudflare Workers
Cloudflare Workers (opens in a new tab) is a serverless platform that allows to run JavaScript/TypeScript at the edge. They use V8 JavaScript engine.
Install Wrangler
Wrangler is a a command line tool for building Cloudflare workers.
Create new project with Wrangler
wrangler generate my-app zaiste/websi-template-cloudflare
Basic web server
main.ts
import { Server } from 'websi'
import { GET } from 'websi/route'
import * as Response from 'websi/response'
const routes = [
GET('/', () => Response.OK('Hello, Websi!'))
]
const server = Server(routes)
export default server
Start
wrangler dev main.ts --local
Open localhost:8787
Add new route
main.ts
const routes = [
GET('/', () => Response.OK(['1', 2, { three: 'four' }])),
GET('/json', () => {
return Response.Created({ foo: 1, bar: 'baz' });
})
]
Deploy
wrangler publish main.ts