git ssb

0+

dangerousbeans / yap



forked from Dominic / yap

Commit 9aa745d5b64d523212242af3c2c8b7a5f69227ea

start moving to standard express/connect middleware

Dominic Tarr committed on 2/9/2019, 6:33:10 AM
Parent: cc1907f44ad723805e449e2380dc1fe439c74871

Files changed

index.jschanged
package.jsonchanged
index.jsView
@@ -9,10 +9,10 @@
99 var toHTML = u.toHTML
1010 var h = u.h
1111 var pull = require('pull-stream')
1212 var toPull = require('stream-to-pull-stream')
13-var CacheWatcher = require('./cache-watcher')
14-
13+var Logger = require('morgan')
14+var BodyParser = require('urlencoded-request-parser')
1515 var Coherence = require('coherence-framework')
1616
1717 var doctype = '<!DOCTYPE html \n PUBLIC "-//W3C//DTD HTML 4.01//EN"\n "http://www.w3.org/TR/html4/strict.dtd">'
1818
@@ -114,15 +114,15 @@
114114 .use('progress', require('./apis/progress')(sbot))
115115 .use('thread', require('./apis/thread')(sbot))
116116 .use('compose', require('./apis/compose')(sbot))
117117 .use('publish', require('./apis/publish')(sbot))
118+ .use('preview', require('./apis/preview')(sbot))
118119 .use('friends', require('./apis/friends')(sbot))
120+ .use('search', require('./apis/search')(sbot))
121+ .use('mentions', require('./apis/mentions')(sbot))
119122
120123 require('http').createServer(_Stack(
121- function (req, res, next) {
122- console.log(req.method, req.url)
123- next()
124- },
124+ Logger(),
125125 //everything breaks if blobs isn't first, but not sure why?
126126 require('ssb-ws/blobs')(sbot, {prefix: '/blobs'}),
127127 /*
128128 some settings we want to store in a cookie:
@@ -141,19 +141,9 @@
141141 return res.end('<h1>yap<img src="/favicon.ico"></h1>')
142142
143143 next()
144144 },
145- function collectBody (req, res, next) {
146- if(req.method !== "POST") return next()
147- else
148- pull(
149- toPull.source(req),
150- pull.collect(function (err, ary) {
151- req.body = Buffer.concat(ary).toString('utf8')
152- next(err)
153- })
154- )
155- },
145+ BodyParser(),
156146 function context (req, res, next) {
157147 req.context = QS.parse(req.headers.cookie||'') || {id: sbot.id}
158148 req.context.id = req.context.id || sbot.id
159149 next()
@@ -161,10 +151,11 @@
161151 //handle posts.
162152 function (req, res, next) {
163153 if(req.method == 'GET') return next()
164154 var id = req.context.id || sbot.id
165- var opts = QS.parse(req.body)
166-
155+// var opts = QS.parse(req.body)
156+ var opts = req.body
157+ console.log('B', opts)
167158 function callApi (path, opts) {
168159 try {
169160 var fn = nested.get(apis, path)
170161 if(!fn) return next()
@@ -177,14 +168,18 @@
177168 // TODO: pass opts.id in, and wether this message
178169 // preview should allow recipient selection, or changing id.
179170 // api.preview can set the shape of the message if it likes.
180171
172+
173+ req.url = '/preview?'+QS.stringify(opts)
174+ coherence(req, res, next)
175+
181176 //XXX this isn't working
182177
183- toHTML(layout.call(self, callApi(['preview'], opts))) (function (err, result) {
184- if(err) next(err)
185- else res.end('<!DOCTYPE html>'+result.outerHTML)
186- })
178+// toHTML(layout.call(self, callApi(['preview'], opts))) (function (err, result) {
179+// if(err) next(err)
180+// else res.end('<!DOCTYPE html>'+result.outerHTML)
181+// })
187182 return
188183 }
189184 actions[opts.type](opts, apply, req, function (err, _opts, context) {
190185 if(err) return next(err)
@@ -228,16 +223,4 @@
228223 coherence
229224 )).listen(8005)
230225 })
231226
232-
233-
234-
235-
236-
237-
238-
239-
240-
241-
242-
243-
package.jsonView
@@ -7,32 +7,35 @@
77 "type": "git",
88 "url": "git://github.com/dominictarr/yap.git"
99 },
1010 "dependencies": {
11+ "body-parser": "^1.18.3",
1112 "coherence-framework": "^1.0.0",
1213 "cont": "^1.0.3",
1314 "explain-error": "^1.0.4",
1415 "hashlru": "^2.2.1",
1516 "html-escape": "^2.0.0",
1617 "hyperscript": "^2.0.2",
1718 "libnested": "^1.4.0",
1819 "markdown-summary": "^1.0.3",
20+ "morgan": "^1.9.1",
1921 "morphdom": "^2.3.3",
2022 "nice-ago": "^1.0.1",
2123 "patchwork-translations": "^1.5.4",
2224 "pull-append": "^1.0.0",
2325 "pull-paramap": "^1.2.2",
2426 "pull-stream": "^3.6.9",
25- "qs": "^6.5.2",
27+ "qs": "^6.6.0",
2628 "querystring": "^0.2.0",
2729 "ssb-markdown": "^3.6.0",
2830 "ssb-mentions": "^0.5.0",
2931 "ssb-ref": "^2.13.6",
3032 "ssb-sort": "^1.1.0",
3133 "ssb-ws": "^5.1.1",
3234 "stack": "^0.1.0",
3335 "stream-to-pull-stream": "^1.7.2",
34- "to-camel-case": "^1.0.0"
36+ "to-camel-case": "^1.0.0",
37+ "urlencoded-request-parser": "^1.0.1"
3538 },
3639 "devDependencies": {
3740 "ssb-client": "^4.6.0"
3841 },

Built with git-ssb-web