UNPKG

1.62 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const constants_1 = require("./constants");
7const mime_types_1 = __importDefault(require("mime-types"));
8async function a_sume(fn, throws) {
9 try {
10 return await fn();
11 }
12 catch (e) {
13 throw throws(e);
14 }
15}
16exports.a_sume = a_sume;
17function s_sume(fn, throws) {
18 try {
19 return fn();
20 }
21 catch (e) {
22 throw throws(e);
23 }
24}
25exports.s_sume = s_sume;
26function filenameOutsideFabLocations(filename) {
27 return filename !== '/server.js' && !filename.startsWith('/_assets/');
28}
29exports.filenameOutsideFabLocations = filenameOutsideFabLocations;
30function getContentType(pathname) {
31 const mimeType = mime_types_1.default.lookup(pathname);
32 return (mimeType && mime_types_1.default.contentType(mimeType)) || constants_1.DEFAULT_MIME_TYPE;
33}
34exports.getContentType = getContentType;
35function getCacheHeaders(immutable) {
36 return immutable ? constants_1.IMMUTABLE_HEADERS : constants_1.NON_IMMUTABLE_HEADERS;
37}
38exports.getCacheHeaders = getCacheHeaders;
39function matchPath(lookup_table, _pathname) {
40 const pathname = decodeURIComponent(_pathname);
41 return (lookup_table[pathname] ||
42 lookup_table[pathname + '.html'] ||
43 lookup_table[`${pathname}${pathname.endsWith('/') ? '' : '/'}index.html`]);
44}
45exports.matchPath = matchPath;
46exports.stripTrailingSlash = (str) => str.replace(/\/$/, '');
47//# sourceMappingURL=helpers.js.map
\No newline at end of file