git ssb

30+

cel / git-ssb-web



Commit 18def954d98179d5edece295ac81d9a404fd86ee

Exit when lost ssb client connection

instead of trying to reconnect which was not working
cel committed on 6/8/2017, 9:51:45 PM
Parent: 1708051538ef367952c9c1478a9a64d2928b4088

Files changed

index.jschanged
package.jsonchanged
server.jschanged
index.jsView
@@ -85,31 +85,21 @@
8585 'issue': true,
8686 'pull-request': true
8787 }
8888
89-var _httpServer
90-
9189 module.exports = {
9290 name: 'git-ssb-web',
9391 version: require('./package').version,
9492 manifest: {},
95- init: function (ssb, config, reconnect) {
96- // close existing server. when scuttlebot plugins get a deinit method, we
97- // will close it in that instead it
98- if (_httpServer)
99- _httpServer.close()
100-
101- var web = new GitSSBWeb(ssb, config, reconnect)
102- _httpSserver = web.httpServer
103-
93 + init: function (ssb, config) {
94 + var web = new GitSSBWeb(ssb, config)
10495 return {}
10596 }
10697 }
10798
108-function GitSSBWeb(ssb, config, reconnect) {
99 +function GitSSBWeb(ssb, config) {
109100 this.ssb = ssb
110101 this.config = config
111- this.reconnect = reconnect
112102
113103 if (config.logging && config.logging.level)
114104 this.logLevel = this.logLevels.indexOf(config.logging.level)
115105 this.ssbAppname = config.appname || 'ssb'
@@ -144,8 +134,10 @@
144134 host: webConfig.host || 'localhost',
145135 port: webConfig.port || 7718
146136 })
147137 this.listen(addr.host, addr.port)
138 +
139 + this.monitorSsbClient()
148140 }
149141
150142 var G = GitSSBWeb.prototype
151143
@@ -478,10 +470,8 @@
478470 ])
479471 }
480472
481473 G.serveError = function (req, err, status) {
482- if (err.message == 'stream is closed')
483- this.reconnect && this.reconnect()
484474 return pull(
485475 pull.once(this.renderError(err, 'h2')),
486476 this.serveTemplate(req, err.name, status || 500)
487477 )
@@ -924,4 +914,20 @@
924914 else
925915 id(null, cb)
926916 }
927917 }
918 +
919 +G.monitorSsbClient = function () {
920 + pull(
921 + function (abort, cb) {
922 + if (abort) throw abort
923 + // leave the stream open
924 + },
925 + this.ssb.gossip.ping(),
926 + pull.drain(null, function (err) {
927 + // exit when the rpc connection ends
928 + if (err) console.error(err)
929 + console.error('sbot client connection closed. aborting')
930 + process.exit(1)
931 + })
932 + )
933 +}
package.jsonView
@@ -31,9 +31,8 @@
3131 "ssb-marked": "^0.6.0",
3232 "ssb-mentions": "^0.1.0",
3333 "ssb-msg-schemas": "^6.1.1",
3434 "ssb-pull-requests": "^1.0.0",
35- "ssb-reconnect": "^0.1.1",
3635 "ssb-ref": "^2.6.2",
3736 "stream-to-pull-stream": "^1.7.2"
3837 },
3938 "homepage": "https://git-ssb.celehner.com/%25q5d5Du%2B9WkaSdjc8aJPZm%2BjMrqgo0tmfR%2BRcX5ZZ6H4%3D.sha256",
server.jsView
@@ -14,10 +14,8 @@
1414
1515 config.listenAddr = config._[1]
1616 config.appname = appName
1717
18-require('ssb-reconnect')(function (cb) {
19- ssbClient(keys, config, cb)
20-}, function (err, ssb, reconnect) {
18 +ssbClient(keys, config, function (err, ssb) {
2119 if (err) throw err
22- Web.init(ssb, config, reconnect)
20 + Web.init(ssb, config)
2321 })

Built with git-ssb-web