Merge branch 'master' of github.com:fraction/oasis into mediator
This commit is contained in:
4
.github/ISSUE_TEMPLATE.md
vendored
Normal file
4
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
**What's the problem you want to solved?**
|
||||
|
||||
**Is there a solution you'd like to recommend?**
|
||||
|
18
.github/ISSUE_TEMPLATE/BUG_REPORT.md
vendored
18
.github/ISSUE_TEMPLATE/BUG_REPORT.md
vendored
@ -1,18 +0,0 @@
|
||||
---
|
||||
name: "🐞 Bug report"
|
||||
about: Report a problem with this software
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**What version of this package are you using?**
|
||||
|
||||
**What operating system, Node.js, and npm version?**
|
||||
|
||||
**What happened?**
|
||||
|
||||
**What did you expect to happen?**
|
||||
|
||||
**Are you willing to submit a pull request to fix this bug?**
|
16
.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
vendored
16
.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
vendored
@ -1,16 +0,0 @@
|
||||
---
|
||||
name: "⭐️ Feature request"
|
||||
about: Request a new feature to be added
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**What version of this package are you using?**
|
||||
|
||||
**What problem do you want to solve?**
|
||||
|
||||
**What do you think is the correct solution to this problem?**
|
||||
|
||||
**Are you willing to submit a pull request to implement this change?**
|
5
.github/PULL_REQUEST_TEMPLATE.md
vendored
5
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,5 +1,4 @@
|
||||
**What is the purpose of this pull request?**
|
||||
**What's the problem you solved?**
|
||||
|
||||
**What changes did you make? (brief overview)**
|
||||
**What solution are you recommending?**
|
||||
|
||||
**Is there anything you'd like reviewers to focus on?**
|
||||
|
16
README.md
16
README.md
@ -9,15 +9,19 @@ some extra tools for debugging, _not_ to support all known message types.
|
||||
|
||||
```console
|
||||
$ oasis --help
|
||||
|
||||
Usage: oasis [options]
|
||||
|
||||
Options:
|
||||
--help Show help [boolean]
|
||||
--version Show version number [boolean]
|
||||
--open Automatically open app in web browser [boolean] [default: true]
|
||||
--host Hostname for web app to listen on[string] [default: "localhost"]
|
||||
--port Port for web app to listen on [number] [default: 3000]
|
||||
--debug Use verbose output for debugging [boolean] [default: false]
|
||||
--version Show version number [boolean]
|
||||
-h, --help Show help [boolean]
|
||||
--open Automatically open app in web browser. Use --no-open to disable.
|
||||
[boolean] [default: true]
|
||||
--offline Don't try to connect to scuttlebutt peers or pubs
|
||||
[boolean] [default: false]
|
||||
--host Hostname for web app to listen on [string] [default: "localhost"]
|
||||
--port Port for web app to listen on [number] [default: 3000]
|
||||
--debug Use verbose output for debugging [boolean] [default: false]
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
63
index.js
Executable file
63
index.js
Executable file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict'
|
||||
|
||||
const yargs = require('yargs')
|
||||
const fs = require('fs').promises
|
||||
const path = require('path')
|
||||
|
||||
const config = yargs
|
||||
.env('OASIS')
|
||||
.help('h')
|
||||
.alias('h', 'help')
|
||||
.usage('Usage: $0 [options]')
|
||||
.options('open', {
|
||||
describe: 'Automatically open app in web browser. Use --no-open to disable.',
|
||||
default: true,
|
||||
type: 'boolean'
|
||||
})
|
||||
.options('offline', {
|
||||
describe: "Don't try to connect to scuttlebutt peers or pubs",
|
||||
default: false,
|
||||
type: 'boolean'
|
||||
})
|
||||
.options('host', {
|
||||
describe: 'Hostname for web app to listen on',
|
||||
default: 'localhost',
|
||||
type: 'string'
|
||||
})
|
||||
.options('port', {
|
||||
describe: 'Port for web app to listen on',
|
||||
default: 3000,
|
||||
type: 'number'
|
||||
})
|
||||
.options('debug', {
|
||||
describe: 'Use verbose output for debugging',
|
||||
default: false,
|
||||
type: 'boolean'
|
||||
})
|
||||
.argv
|
||||
|
||||
// This hides arguments from other upstream modules who might parse them.
|
||||
//
|
||||
// Unfortunately some modules think that our CLI options are meant for them,
|
||||
// and since there's no way to disable that behavior (!) we have to hide them
|
||||
// manually by setting the args property to an empty array.
|
||||
process.argv = []
|
||||
|
||||
if (config.debug) {
|
||||
process.env.DEBUG = 'oasis,oasis:*'
|
||||
}
|
||||
|
||||
// Awful hack to get the offline config setting deep into src/pages/models/lib/server.js
|
||||
process.env.OASIS_OFFLINE = '' + config.offline
|
||||
|
||||
const app = require('./src/app')
|
||||
|
||||
const start = async () => {
|
||||
const filePath = path.join(__dirname, 'README.md')
|
||||
config.readme = await fs.readFile(filePath, 'utf8')
|
||||
app(config)
|
||||
}
|
||||
|
||||
start()
|
@ -6,12 +6,19 @@ module.exports = () =>
|
||||
yargs
|
||||
.scriptName('oasis')
|
||||
.env('OASIS')
|
||||
.help('h')
|
||||
.alias('h', 'help')
|
||||
.usage('Usage: $0 [options]')
|
||||
.options('open', {
|
||||
describe: 'Automatically open app in web browser',
|
||||
describe: 'Automatically open app in web browser. Use --no-open to disable.',
|
||||
default: true,
|
||||
type: 'boolean'
|
||||
})
|
||||
.options('offline', {
|
||||
describe: "Don't try to connect to scuttlebutt peers or pubs",
|
||||
default: false,
|
||||
type: 'boolean'
|
||||
})
|
||||
.options('host', {
|
||||
describe: 'Hostname for web app to listen on',
|
||||
default: 'localhost',
|
||||
|
@ -38,7 +38,7 @@ const ssb = require('./ssb')
|
||||
|
||||
// Create "cooler"-style interface from SSB connection.
|
||||
// This handle is passed to the models for their convenience.
|
||||
const cooler = ssb()
|
||||
const cooler = ssb({ offline: config.offline })
|
||||
|
||||
const {
|
||||
about,
|
||||
@ -509,8 +509,10 @@ http({ host, port, routes })
|
||||
|
||||
const uri = `http://${host}:${port}/`
|
||||
|
||||
const isDebugEnabled = debug.enabled
|
||||
debug.enabled = true
|
||||
debug(`Listening on ${uri}`)
|
||||
debug.enabled = isDebugEnabled
|
||||
|
||||
if (config.open === true) {
|
||||
open(uri)
|
||||
|
43
src/ssb.js
43
src/ssb.js
@ -5,13 +5,20 @@
|
||||
// native support for Promises in the MuxRPC module and auto-generated manifest
|
||||
// files in the SSB-Client module.
|
||||
|
||||
const debug = require('debug')('oasis')
|
||||
const ssbClient = require('ssb-client')
|
||||
const ssbConfig = require('ssb-config')
|
||||
const flotilla = require('@fraction/flotilla')
|
||||
const debug = require('debug')('oasis')
|
||||
|
||||
const server = flotilla(ssbConfig)
|
||||
|
||||
const log = (...args) => {
|
||||
const isDebugEnabled = debug.enabled
|
||||
debug.enabled = true
|
||||
debug(...args)
|
||||
debug.enabled = isDebugEnabled
|
||||
}
|
||||
|
||||
const rawConnect = () => new Promise((resolve, reject) => {
|
||||
ssbClient({
|
||||
manifest: {
|
||||
@ -53,25 +60,23 @@ const rawConnect = () => new Promise((resolve, reject) => {
|
||||
})
|
||||
})
|
||||
|
||||
debug.enabled = true
|
||||
|
||||
let handle
|
||||
|
||||
const createConnection = () => {
|
||||
const createConnection = (config) => {
|
||||
handle = new Promise((resolve) => {
|
||||
rawConnect().then((ssb) => {
|
||||
debug('Using pre-existing Scuttlebutt server instead of starting one')
|
||||
log('Using pre-existing Scuttlebutt server instead of starting one')
|
||||
resolve(ssb)
|
||||
}).catch(() => {
|
||||
debug('Initial connection attempt failed')
|
||||
debug('Starting Scuttlebutt server')
|
||||
server({ ws: { http: false } })
|
||||
log('Initial connection attempt failed')
|
||||
log('Starting Scuttlebutt server')
|
||||
server(config)
|
||||
const connectOrRetry = () => {
|
||||
rawConnect().then((ssb) => {
|
||||
debug('Retrying connection to own server')
|
||||
log('Retrying connection to own server')
|
||||
resolve(ssb)
|
||||
}).catch((e) => {
|
||||
debug(e)
|
||||
log(e)
|
||||
connectOrRetry()
|
||||
})
|
||||
}
|
||||
@ -83,8 +88,22 @@ const createConnection = () => {
|
||||
return handle
|
||||
}
|
||||
|
||||
module.exports = () => {
|
||||
createConnection()
|
||||
module.exports = ({ offline }) => {
|
||||
if (offline) {
|
||||
log('Offline mode activated - not connecting to scuttlebutt peers or pubs')
|
||||
log('WARNING: offline mode cannot control the behavior of pre-existing servers')
|
||||
}
|
||||
|
||||
const config = {
|
||||
conn: {
|
||||
autostart: !offline
|
||||
},
|
||||
ws: {
|
||||
http: false
|
||||
}
|
||||
}
|
||||
|
||||
createConnection(config)
|
||||
return {
|
||||
connect () {
|
||||
// This has interesting behavior that may be unexpected.
|
||||
|
Reference in New Issue
Block a user