return function (request) { try { return func(request); } catch (error) { if (!(error instanceof rv.TupleDoesNotExist)) throw error; throw http.NotFound(error.message); } };
return function (request) { if (!request.path.startsWith(template.staticURLPrefix)) return func(request); var descr = request.path.substring(template.staticURLPrefix.length); var storage = require.main.storage; var content; var cacheControl; if (storage.repo) { var slashIndex = descr.indexOf('/'); if (slashIndex == -1) throw http.NotFound(); var commit = descr.substring(0, slashIndex); var path = descr.substring(slashIndex + 1); try { content = storage.repo.getStorage(commit).read( template.staticPathPrefix + path); } catch (_) { throw http.NotFound(); } cacheControl = 'max-age=315360000'; } else { try { content = storage.read(template.staticPathPrefix + descr); } catch (_) { throw http.NotFound(); } cacheControl = 'no-cache'; } var contentType = 'application/octet-stream'; var dotIndex = descr.lastIndexOf('.'); if (dotIndex != -1) { var extension = descr.substring(dotIndex + 1).toLowerCase(); if (contentTypes.hasOwnProperty(extension)) contentType = contentTypes[extension]; } return new exports.Response( content, http.OK, { 'Cache-Control': cacheControl, 'Content-Type': contentType }); };