darkflare
darkflare is a folder-based router - similar to Next.js - for Cloudflare Workers. It generates a neat JavaScript bundle from your TypeScript code which can then be deployed to Cloudflare Workers straight away.
Setup
Install the CLI.
Deno
v1.30.0or later should be installed.deno install -n darkflare -f -A https://deno.land/x/darkflare@v6.4.0/cli/mod.ts
Add a import map.
deno.json{ "imports": { "darkflare": "https://deno.land/x/darkflare@v6.4.0/mod.ts", "darkflare/authenticator": "https://deno.land/x/darkflare@v6.4.0/authenticator/mod.ts", "darkflare/jwt": "https://deno.land/x/darkflare@v6.4.0/jwt/mod.ts", "darkflare/oauth2": "https://deno.land/x/darkflare@v6.4.0/oauth2/mod.ts", "darkflare/realm": "https://deno.land/x/darkflare@v6.4.0/realm/mod.ts", "darkflare/s3": "https://deno.land/x/darkflare@v6.4.0/s3/mod.ts", "darkflare/x": "https://deno.land/x/darkflare@v6.4.0/x/mod.ts" } }
Routes
Make sure to create a api folder for all your route files.
e.g. /api/hello.ts
import { Get } from 'darkflare'
Get({}, () => {
return 'Hello World!'
})Types:
Basic Routes
/api/example.tsβ/example/api/a.tsβ/a/api/b.tsβ/bIndex Routes
/api/mod.tsβ//api/example/mod.tsβ/exampleNested Routes
/api/a/b.tsβ/a/b/api/a/b/c/d.tsβ/a/b/c/dDynamic Routes
/api/[example].tsβ/:example
Triggers:
GetPostPutPatchDeleteHead
Configuration
Create a file named darkflare.ts in your project root and add the below
content to configure darkflare.
import { Darkflare } from 'darkflare'
new Darkflare({
...
})
// or, with environment variables:
import { Darkflare } from 'darkflare'
new Darkflare(env => ({
...
}))Options:
name(optional)This option is required if
cacheis set to 1 or higher and the cache should persist during re-deployments.The name for your app.
base(optional)The base for your app, e.g. /api.
cors(optional)The allowed origin for incoming requests.
cache(optional)Cache responses for a given amount of seconds.
onError()(optional){ onError: ; ;((err, request) => { return new Response(err) // e.g. MALFORMED COOKIES }) }
realm(optional)appdatabasetoken
s3(optional)accountclientidsecret
encryption(optional)account
oauth2(optional)githubclientIdclientSecret