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.29.0
or 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
{ "importMap": "./map.json" }
map.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
β/b
Index Routes
/api/mod.ts
β/
/api/example/mod.ts
β/example
Nested Routes
/api/a/b.ts
β/a/b
/api/a/b/c/d.ts
β/a/b/c/d
Dynamic Routes
/api/[example].ts
β/:example
Triggers:
Get
Post
Put
Patch
Delete
Head
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
cache
is 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)app
database
token
s3
(optional)account
client
id
secret
encryption
(optional)account
oauth2
(optional)github
clientId
clientSecret