fastify-hyperdrive

3.0.1 • Public • Published

fastify-hyperdrive

Serve files from Hyperdrive as a fastify route

Usage

npm i --save fastify-hyperdrive

# or

yarn add fastify-hyperdrive
const fastifyHyperdrive = require('fastify-hyperdrive')

// Make a function that maps keys to hyperdrive instances
// Make sure you have networking set up for them
// Either use `drive.promises` from the stock Hyperdrive repo
// Or use the Hyperdrive constructor from dat-sdk
// Check out `test.js` for more info
async function getHyperdrive(key) {
  // If you use the stock version of hyperdrive
  return hyperdrive(key).promises
  // Or if you use dat-sdk or hyperdrive-promise
  return hyperdrive(key)
}

fastify.get('/:key/*`, fastifyHyperdrive(getHyperdrive))
// This might be needed for Range requests?
fastify.head('/:key/*', fastifyHyperdrive(getHyperdrive))

API

fastifyHyperdrive(async getHyperdrive(key)) => (request, reply) => Promise

Create a route handler for fastify which will resolve paths within hyperdrives. The return value is the callback expected in fastify.get()

Package Sidebar

Install

npm i fastify-hyperdrive

Weekly Downloads

9

Version

3.0.1

License

AGPL-3.0

Unpacked Size

42 kB

Total Files

6

Last publish

Collaborators

  • rangermauve