dat-dns-middleware

1.0.2-alpha • Public • Published

dat-dns-middleware

Stability npm version JavaScript Style Guide Build Status Coverage Status Greenkeeper badge

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.

License

Apache-2.0

Readme

Keywords

Package Sidebar

Install

npm i dat-dns-middleware

Weekly Downloads

3

Version

1.0.2-alpha

License

Apache-2.0

Unpacked Size

7.38 kB

Total Files

6

Last publish

Collaborators

  • garbados