https://github.com/rangermauve/fastify-hyperdrive
Serve files from Hyperdrive as a fastify route
https://github.com/rangermauve/fastify-hyperdrive
Last synced: 4 months ago
JSON representation
Serve files from Hyperdrive as a fastify route
- Host: GitHub
- URL: https://github.com/rangermauve/fastify-hyperdrive
- Owner: RangerMauve
- License: agpl-3.0
- Created: 2020-07-28T15:23:45.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-18T00:57:01.000Z (almost 4 years ago)
- Last Synced: 2025-01-04T19:34:26.853Z (5 months ago)
- Language: JavaScript
- Size: 300 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-hyperdrive
Serve files from Hyperdrive as a fastify route## Usage
```
npm i --save fastify-hyperdrive# or
yarn add fastify-hyperdrive
``````js
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()`](https://www.fastify.io/docs/latest/Routes/#shorthand-declaration)