In-memory Dat to HTTP gateway
Clone or download
Pull request Compare This branch is 28 commits ahead, 3 commits behind garbados:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Stability NPM Version JavaScript Style Guide Build Status Coverage Status

A configurable in-memory Dat-to-HTTP gateway, so you can visit Dat archives from your browser.

If you want a browser that can visit Dat archives, check out Beaker.


To get the dat-gateway command for running your own gateway, use npm:

npm i -g dat-gateway

Public Gateways:


You can run dat-gateway to start a gateway server that listens on port 3000. You can also configure it! You can print usage information with dat-gateway -h:

$ dat-gateway -h

  --version       Show version number                                  [boolean]
  --config        Path to JSON config file
  --port, -p      Port for the gateway to listen on.             [default: 3000]
  --dir, -d       Directory to use as a cache.
                                            [string] [default: "~/.dat-gateway"]
  --max, -m       Maximum number of archives allowed in the cache. [default: 20]
  --period        Number of milliseconds between cleaning the cache of expired
                  archives.                                     [default: 60000]
  --ttl, -t       Number of milliseconds before archives expire.
                                                               [default: 600000]
  --redirect, -r  Whether to use subdomain redirects            [default: false]
  -h, --help      Show help                                            [boolean]

You can visit Dat archives through the gateway using a route like this:


For example:


The gateway will even resolve URLs using Dat-DNS:


The gateway will peer archives until they expire from the cache, at which point it proactively halts them and deletes them from disk.

The gateway also supports replicating a hyperdrive instance using websockets

const Websocket = require('websocket-stream')
const hyperdrive = require('hyperdrive')

const key = 'c33bc8d7c32a6e905905efdbf21efea9ff23b00d1c3ee9aea80092eaba6c4957'
const url = `ws://localhost:3000/${key}`

const archive = hyperdrive('./somewhere', key)

archive.once('ready', () => {
  const socket = websocket(url)

  // Replicate through the socket

Subdomain redirection

By default dat-gateway will serve all dats from the same origin. This means that dats using absolute URLs (starting with /) will be broken. This also means that all dats will share the same localStorage and indexedDB instances which can cause security issues.

In order to resolve these issues, you can use the --redirect flag in conjunction with the domain to have each dat served on a subdomain.

For example,{datkey}/index.html will be redirected to http://{datkey32} which will serve the file from localhost, but at a different domain, ensuring the browser isolates all the contents from each other.

Please note that due to limitations in how URLs work, the dat key will be converted to it's base32 representation instead of hexadecimal using this library


All contributions are welcome: bug reports, feature requests, "why doesn't this work" questions, patches for fixes and features, etc. For all of the above, file an issue or submit a pull request.