Differences From
Artifact [4d69f275c0]:
158 158 var redirto: lib.str.acc redirto:compose('/post/',{idbuf,idlen}) defer redirto:free()
159 159 co:reroute(redirto.buf)
160 160 end
161 161 end
162 162
163 163 terra http.timeline(co: &lib.srv.convo, mode: hpath)
164 164 lib.render.timeline(co,lib.trn(mode.ptr == nil, rstring{ptr=nil}, mode.ptr[1]))
165 - return
165 +end
166 +
167 +terra http.documentation(co: &lib.srv.convo, path: hpath)
168 + if path.ct == 2 then
169 + lib.render.docpage(co,path(1))
170 + elseif path.ct == 1 then
171 + lib.render.docpage(co, rstring.null())
172 + else
173 + co:complain(404, 'no such documentation', 'invalid documentation URL')
174 + end
166 175 end
167 176
168 177 do local branches = quote end
169 178 local filename, flen = symbol(&int8), symbol(intptr)
170 179 local page = symbol(lib.http.page)
171 180 local send = label()
172 181 local storage = data.stmap
................................................................................
203 212 co:reroute('/s/default-avatar.webp')
204 213 end
205 214
206 215 -- entry points
207 216 terra r.dispatch_http(co: &lib.srv.convo, uri: lib.mem.ptr(int8), meth: method.t)
208 217 lib.dbg('handling URI of form ', {uri.ptr,uri.ct})
209 218 co.navbar = lib.render.nav(co)
210 - lib.dbg('got nav ', {co.navbar.ptr,co.navbar.ct}, "||", co.navbar.ptr)
211 219 -- some routes are non-hierarchical, and can be resolved with a simple strcmp
212 220 -- we run through those first before giving up and parsing the URI
213 221 if uri.ptr[0] ~= @'/' then
214 222 co:complain(404, 'what the hell', 'how did you do that')
215 223 return
216 224 elseif uri.ct == 1 then -- root
217 225 if (co.srv.cfg.pol_sec == lib.srv.secmode.private or
................................................................................
251 259 return
252 260 else -- hierarchical routes
253 261 var path = lib.http.hier(uri) defer path:free()
254 262 if path.ptr[0]:cmp(lib.str.lit('user')) then
255 263 http.actor_profile_uid(co, path, meth)
256 264 elseif path.ptr[0]:cmp(lib.str.lit('tl')) then
257 265 http.timeline(co, path)
266 + elseif path.ptr[0]:cmp(lib.str.lit('doc')) then
267 + if meth ~= method.get and meth ~= method.head then goto wrongmeth end
268 + http.documentation(co, path)
258 269 else goto notfound end
259 270 return
260 271 end
261 272
262 273 ::wrongmeth:: co:complain(405, 'method not allowed', 'that method is not meaningful for this endpoint') do return end
263 274 ::notfound:: co:complain(404, 'not found', 'no such resource available') do return end
264 275 end