index.jsView |
---|
9 | 9 | var toHTML = u.toHTML |
10 | 10 | var h = u.h |
11 | 11 | var pull = require('pull-stream') |
12 | 12 | 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') |
15 | 15 | var Coherence = require('coherence-framework') |
16 | 16 | |
17 | 17 | var doctype = '<!DOCTYPE html \n PUBLIC "-//W3C//DTD HTML 4.01//EN"\n "http://www.w3.org/TR/html4/strict.dtd">' |
18 | 18 | |
114 | 114 | .use('progress', require('./apis/progress')(sbot)) |
115 | 115 | .use('thread', require('./apis/thread')(sbot)) |
116 | 116 | .use('compose', require('./apis/compose')(sbot)) |
117 | 117 | .use('publish', require('./apis/publish')(sbot)) |
| 118 | + .use('preview', require('./apis/preview')(sbot)) |
118 | 119 | .use('friends', require('./apis/friends')(sbot)) |
| 120 | + .use('search', require('./apis/search')(sbot)) |
| 121 | + .use('mentions', require('./apis/mentions')(sbot)) |
119 | 122 | |
120 | 123 | require('http').createServer(_Stack( |
121 | | - function (req, res, next) { |
122 | | - console.log(req.method, req.url) |
123 | | - next() |
124 | | - }, |
| 124 | + Logger(), |
125 | 125 | |
126 | 126 | require('ssb-ws/blobs')(sbot, {prefix: '/blobs'}), |
127 | 127 | |
128 | 128 | some settings we want to store in a cookie: |
141 | 141 | return res.end('<h1>yap<img src="/favicon.ico"></h1>') |
142 | 142 | |
143 | 143 | next() |
144 | 144 | }, |
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(), |
156 | 146 | function context (req, res, next) { |
157 | 147 | req.context = QS.parse(req.headers.cookie||'') || {id: sbot.id} |
158 | 148 | req.context.id = req.context.id || sbot.id |
159 | 149 | next() |
161 | 151 | |
162 | 152 | function (req, res, next) { |
163 | 153 | if(req.method == 'GET') return next() |
164 | 154 | var id = req.context.id || sbot.id |
165 | | - var opts = QS.parse(req.body) |
166 | | - |
| 155 | + |
| 156 | + var opts = req.body |
| 157 | + console.log('B', opts) |
167 | 158 | function callApi (path, opts) { |
168 | 159 | try { |
169 | 160 | var fn = nested.get(apis, path) |
170 | 161 | if(!fn) return next() |
177 | 168 | |
178 | 169 | |
179 | 170 | |
180 | 171 | |
| 172 | + |
| 173 | + req.url = '/preview?'+QS.stringify(opts) |
| 174 | + coherence(req, res, next) |
| 175 | + |
181 | 176 | |
182 | 177 | |
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 | + |
| 179 | + |
| 180 | + |
| 181 | + |
187 | 182 | return |
188 | 183 | } |
189 | 184 | actions[opts.type](opts, apply, req, function (err, _opts, context) { |
190 | 185 | if(err) return next(err) |
228 | 223 | coherence |
229 | 224 | )).listen(8005) |
230 | 225 | }) |
231 | 226 | |
232 | | - |
233 | | - |
234 | | - |
235 | | - |
236 | | - |
237 | | - |
238 | | - |
239 | | - |
240 | | - |
241 | | - |
242 | | - |
243 | | - |