Middleware

API routes have a lightweight middleware concept. Export an array of async function handlers, and they will be run in the order you define.

export const get = [one, two]

async function one (req) {
  console.log('hi from one')
  req.first = true
}

async function two (req) {
  console.log('hi from two')
  const second = false

  return { json: [req.first, second] }
}
🎩

Protip: Exit middleware early by returning a response.


Community Resources

GitHub

Visit Enhance on GitHub.

Discord

Join our Discord server to chat about development and get help from the community.

Mastodon

Follow Enhance in the Fediverse. We're huge fans of the IndieWeb!