3 var roomContextService
= require('gitter-web-rooms/lib/room-context-service');
4 var StatusError
= require('statuserror');
5 var uriContextAsBrowserState
= require('gitter-web-uri-resolver/lib/uri-context-as-browser-state');
8 * This API is currently a work in progress and shouldn't be
9 * relied upon until it is ratified.
11 function resolve(req
, res
, next
) {
12 var uri
= req
.params
[0];
14 return roomContextService
15 .findContextForUri(req
.user
, uri
, { ignoreCase
: true })
19 .then(function(uriContext
) {
21 throw new StatusError(404);
24 this.uriContext
= uriContext
;
26 if (uriContext
.ownUrl
) {
30 return uriContext
.policy
.canRead();
32 .then(function(access
) {
33 if (!access
) throw new StatusError(404);
35 var browserState
= uriContextAsBrowserState(this.uriContext
);
36 if (!browserState
) throw new StatusError(404);
39 * TODO: consider adding Cache Control headers to this
41 * `res.set('Cache-Control', 'max-age=3600');`
44 res
.send(browserState
);
49 module
.exports
= resolve
;