// Resolve an existing ID. We break off the prefix and use it to work out which resolver to use. router.get('/:id', function(req, res, next) { var prefix = req.params.id.match(splitPrefixRe)[2] || ''; var id = req.params.id.match(splitPrefixRe)[3]; var resolver; var serviceOptions = options.shareUrlPrefixes[prefix]; if (!serviceOptions) { console.error('Share: Unknown prefix to resolve "' + prefix + '", id "' + id + '"'); return res.status(400).send('Unknown share prefix "' + prefix + '"'); } else { resolver = { 'gist': resolveGist, 's3': resolveS3 }[serviceOptions.service.toLowerCase()]; } resolver(serviceOptions, id).then(function(content) { res.send(content); }).catch(rperrors.TransformError, function (reason) { console.error(JSON.stringify(reason, null, 2)); res.status(500).send(reason.cause.message); }).catch(function(reason) { console.warn(JSON.stringify(reason.response, null, 2)); res.status(404) // probably safest if we always return 404 rather than whatever the upstream provider sets. .send(reason.error); }); });
.status(201) .json({ id: id, path: resPath, url: resUrl }); }).catch(rperrors.TransformError, function (reason) { console.error(JSON.stringify(reason, null, 2)); res.status(500).json({ message: reason.cause.message });