hub.js - amark/gun GitHub Wiki
lib/hub.js (server-side only)
Host your website on Gun !
The hub feature is an optional feature that allows you to watch a directory and upload all of its content on the database (only text files are supported for now).
How to use it ?
First, you must install Chokidar
. When itβs done, import hub.js
:
const hub = require('gun/lib/hub'); // Classic
// or
import hub from βgun/lib/hubβ; // ES6βs way
// then
hub.watch(/* The path you want to watch. */)
Options
what
(String) - Which directory hub
should watch.
options
(Object) - Change the behavior of hub.
// Available options
{
msg: true // or false | disable or enable update messages,
hubignore: false // or true | Activate the .hubignore feature
}
.hubignore
file
The It'd be really dangerous if you upload all your files on the DB !
The purpose of the .hubignore
is to give you the possibility to choose what files are watched by hub & sent to Gun ! It works exactly as the .gitignore
file. It must be in the root of the folder you're watching.
# Very important API KEY !
/whatever/api-key.txt
.
βββ index.html
βββ .hubignore
βββ whatever/
βββ api-key.txt
Example
Given this directory :
.
βββ directory/
βββ index.html
βββ .hubignore
βββ whatever/
βββ style.css
βββ api-key.txt
// Basic usage.
const hub = require(βgun/lib/hubβ); // OR import hub from βgun/lib/hubβ;
hub.watch(β./directoryβ);
gun.get(βhubβ).on(data => {
console.log(data[β/directory/index.htmlβ]) // Get the content of index.html
console.log(data[β/directory/folder/whatever.cssβ]) // Get the content of whatever.css
})
# .hubignore
/whatever/api-key.txt # Won't be uploaded !