Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/garbados/dat-gateway
In-memory Dat to HTTP gateway
https://github.com/garbados/dat-gateway
Last synced: about 1 month ago
JSON representation
In-memory Dat to HTTP gateway
- Host: GitHub
- URL: https://github.com/garbados/dat-gateway
- Owner: garbados
- Created: 2017-09-24T18:43:47.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-18T04:00:00.000Z (about 4 years ago)
- Last Synced: 2024-10-19T21:47:24.038Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://dat.bovid.space/
- Size: 182 KB
- Stars: 61
- Watchers: 7
- Forks: 13
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dat-gateway
[![Stability](https://img.shields.io/badge/stability-experimental-orange.svg)](https://nodejs.org/api/documentation.html#documentation_stability_index)
[![NPM Version](https://img.shields.io/npm/v/dat-gateway.svg)](https://www.npmjs.com/package/dat-gateway)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Build Status](https://travis-ci.org/garbados/dat-gateway.svg?branch=master)](https://travis-ci.org/garbados/dat-gateway)
[![Coverage Status](https://img.shields.io/coveralls/github/garbados/dat-gateway/master.svg)](https://coveralls.io/github/garbados/dat-gateway?branch=master)A configurable in-memory [Dat](https://datproject.org/)-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](https://beakerbrowser.com/).
## Install
To get the `dat-gateway` command for running your own gateway, use [`npm`](https://www.npmjs.com/):
```
npm i -g dat-gateway
```If you have [`npx`](https://github.com/zkat/npx) installed, it's even shorter:
```
npx dat-gateway
```## Public Gateways:
- http://gateway.mauve.moe:3000/ (Hosted by @RangerMauve)
- https://pamphlets.me/ (Hosted by @brechtcs)
- https://dat.bovid.space/ (Original gateway from @garbados)
- https://dat.hypersource.club (Hosted by @jwerle)## Usage
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
dat-gatewayOptions:
--version Show version number [boolean]
--config Path to JSON config file
--host, -l Host or ip for the gateway to listen on. [default: "0.0.0.0"]
--port, -p Port for the gateway to listen on. [default: 3000]
--dat-port, -P Port for Dat to listen on. Defaults to Dat's internal
defaults. [default: null]
--dir, -d Directory to use as a cache.
[string] [default: "~/.cache/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]
--loopback, -L What hostname to use when serving locally.
[default: "dat.localhost"]
-h, --help Show help [boolean]
```You can visit Dat archives through the gateway using a route like this:
```
http://localhost:3000/{datKey}/{path...}
```For example:
```
http://localhost:3000/40a7f6b6147ae695bcbcff432f684c7bb5291ea339c28c1755896cdeb80bd2f9/assets/img/beaker-0.7.gif
```The gateway will even resolve URLs using [Dat-DNS](https://github.com/beakerbrowser/beaker/wiki/Authenticated-Dat-URLs-and-HTTPS-to-Dat-Discovery):
```
http://localhost:3000/garbados.hashbase.io/icons/favicon.ico
```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](https://github.com/maxogden/websocket-stream)
```javascript
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
socket.pipe(archive.replicate()).pipe(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 `host` parameter to have each dat served on a subdomain.
For example, `http://{host}:{port}/{datkey}/index.html` will be redirected to `http://{datkey32}.{host}:{port}/index.html` 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](https://github.com/RangerMauve/hex-to-32)
## Serving on localhost
Running a gateway locally for personal use is a great idea, but by default dat-gateway uses `dat.localhost` as its hostname when serving to the local machine. Firefox [does not support '\*.localhost' domains](https://bugzilla.mozilla.org/show_bug.cgi?id=1433933) and so this behavior breaks the gateway for Firefox users.
To fix this, use the `-L, --loopback` flag to specify `localhost` as the loopback hostname, like so:
```
$ dat-gateway -L localhost
```This will cause dat-gateway to use `localhost` as its domain name, which Firefox supports just fine.
## Contributions
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](https://github.com/garbados/dat-gateway/issues) or [submit a pull request](https://github.com/garbados/dat-gateway/pulls).
## License
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)