A pub
An ssb-db2 database and http API server.
For the planetary instance, see the render.com dashboard
The live http API -- https://pub2.onrender.com/
See how the caps value is generated
Install as a dependency:
$ npm i -S @planetary-ssb/pub
Install as an app (git clone):
$ git clone git@github.com:planetary-social/planetary-pub.git pub
$ node ./index.js
var createSbot = require('@planetary-ssb/pub/pub')
var Viewer = require('@planetary-ssb/pub/viewer')
createSbot((err, sbot) => {
if (err) throw err
var viewer = Viewer(sbot)
viewer.listen(PORT, '0.0.0.0', (err, address) => {
if (err) return cb(err)
console.log(`Server is now listening on ${address}`)
})
})
We're using husky to automatically run tests and lint when you push to the 'main' branch.
git push --no-verify
Add the test script as a git hook. This way we can check which branch we're on in the git hook.
npx husky add .husky/pre-push "./test/githook/prepush.sh"
NODE_ENV=test node test/viewer.js | npx tap-spec
NODE_ENV=test node test/index.js | npx tap-spec
NODE_ENV=staging-local node index.js
NODE_ENV=staging-local node --max-old-space-size=512 index.js
NODE_ENV=staging-local node --inspect-brk --max-old-space-size=512 index.js
then open chrome://inspect/
Connect to your pub
In another terminal/machine:
// need to get this address from the other sbot
var addr = 'net:localhost:62042~shs:LYknR3SSOEOrXD2yEQcHhIrUQmsPNo5+3ETvfjuf3Mw='
// the `ssb-conn` plugin
sbot.conn.connect(addr, (err, ssb) => {
if (err) return console.log('errrrr', err)
console.log('**connected to pub**', !!ssb)
})
See .env.example
NODE_ENV="test"
FAUNA_SECRET="123"
TEST_PW="my-password"
Set NODE_ENV
to test
to re-write the DB with test data when the server starts.
$ NODE_ENV=test npm start
Set NODE_ENV
to staging
to automatically connect to and follow the pubs in ./pubs.json
.
$ NODE_ENV=staging npm start
A NODE_ENV
of staging-local
means that you will connect to and follow other pubs automatically like above, but the DB will use a different directory, db-staging
. Because that way you can run tests on your local machine using the db
folder, and also make a pub that uses the folder db-staging
for data that is more real.
$ NODE_ENV=staging-local npm start
Use a 512 MB limit on memory (so you can tell if it uses too much)
NODE_ENV=staging-local node --max-old-space-size=512 index.js
These are the endpoints available if you call the http API
=> sbot.id | NODE_ENV
/
=>
address -- net:localhost:62042~shs:LYknR3SSOEOrXD2yEQcHhIrUQmsPNo5+3ETvfjuf3Mw=
public keys -- @LYknR3SSOEOrXD2yEQcHhIrUQmsPNo5+3ETvfjuf3Mw=.ed25519
NODE_ENV -- test
=> thread of messages related to that id, or just the message with id
/%1HbhmsEc4OCiLD5o8raRl+x8QUO7Y6oZ3C57vwNM78c=.sha256
=> return a blob, indexed by blob hash
/blob/&SNZQDvykMENRmJMVyLfG20vlvgelGwj03C3YjWEi0JQ=.sha256
get a feed by display name. will return an array of JSON messages
/feed/nichoth
Get all messages tagged with #tagName.
/tag/example
Get someone's avatar and description by username
/profile/nichoth
Get the number of posts, number of followers, and number of users followed for a given username
/counts/nichoth
{
key: '%1HbhmsEc4OCiLD5o8raRl+x8QUO7Y6oZ3C57vwNM78c=.sha256',
value: {
previous: '%CCceib4KRShqtaN95hPGl0qORtefsTEb/qwbB0YZVyQ=.sha256',
sequence: 3,
author: '@lV5MISER9oGaZJ7OLhlsUNVWHu982USYgMEWfIs6le0=.ed25519',
timestamp: 1638820387617,
hash: 'sha256',
content: { type: 'post', text: 'three' },
signature: 'E2sC6mH9F+HhfIVl6MjobLdZX6RG3QRwFBiMoT5vb64L6XkS5TutPh2gYRRIqKZSzzW5ld0sLvvEc81pcrRtCQ==.sig.ed25519'
},
timestamp: 1638820387618
}
see pull-files multiblob ssb-blobs
blobId
:
&SNZQDvykMENRmJMVyLfG20vlvgelGwj03C3YjWEi0JQ=.sha256
https://github.com/ssbc/ssb-server#install
#!/bin/bash
while true; do
ssb-server start
sleep 3
done
sbot publish --type about --about "@your.public.id.here" --publicWebHosting