dat-dns-middleware
v1.0.2-alpha
Published
Middleware for Connect and Express to serve static files over the Dat network.
Downloads
5
Readme
dat-dns-middleware
Middleware for Connect and Express to serve static files over the peer-to-peer Dat network. Use it to serve your static files over Dat:
const datDnsMiddleware = require('dat-dns-middleware')
const express = require('express')
const staticRoot = 'static'
const app = express()
app.use(express.static(staticRoot))
app.use(datDnsMiddleware(staticRoot))
...
The middleware catches requests to /.well-known/dat
and responds in the Dat-DNS format:
{datKey}
TTL={ttl}
This allows things like Beaker Browser and dat-fox to retrieve your website's static assets from peers in the Dat network.
Install
Use npm to include dat-dns-middleware as a dependency:
npm i -S dat-dns-middleware
Now just require
it in your application:
const datDnsMiddleware = require('dat-dns-middleware')
const express = require('express')
const staticRoot = 'static'
const app = express()
app.use(express.static(staticRoot))
app.use(datDnsMiddleware(staticRoot))
Usage
The library exports one function:
datDnsMiddleware(dir, ttl = 3600)
Example:
const datDnsMiddleware = require('dat-dns-middleware')
const middleware = datDnsMiddleware('static')
Parameters:
dir
: Path to the directory to use as a Dat archive.ttl
: Expiration time for the DNS listing in seconds. Defaults to one hour.
Development
Download the source with git and run the test suite with npm:
git clone https://github.com/garbados/dat-dns-middleware
cd dat-dns-middleware
npm install
npm test
Here's a one-liner for checking test coverage:
npx nyc npm test
Contributing
To report bugs or request features, file an issue. If you want to merge code, file a pull request. I reserve sole discretion for the moderation of this project.