darkflare v4
Setup
npm i darkflare
npm i darkflare@canary
Configuration
Create a new file named darkflare.json
in the root directory of your project.
{
"$schema": "https://darkflare.run/schema.json"
// use auto-complete
}
name
- the name for your app (used for caching)
base
- the base for your app, e.g. /api
cors
- the allowed origin for incoming requests
cache
- cache responses for a given amount of seconds
passThroughOnException
- pass request to origin on exception
Usage
Routes
Create a new file in your /src/routes
directory and name it whatever you want the endpoint to be. If you want a dynamic route, add a [
to the beginning and a ]
to the end of the name to access it in ctx.req.parameters
e.g. /src/routes/index.ts
👉 /
or /src/routes/example.ts
👉 /example
or /src/routes/[key]/whatever.ts
👉 /:key/whatever
import { useRoute, Type } from 'darkflare'
const Get = useRoute({
schema: {
body: Type.String()
}
}, async ctx => {
console.log(ctx.req.body)
return 'Hello World'
})
export { Get }
Linting
darkflare lint
darkflare lint --fix
Building
darkflare build