1 | import { DEFAULT_MIME_TYPE, IMMUTABLE_HEADERS, NON_IMMUTABLE_HEADERS } from './constants';
|
2 | import mime from 'mime-types';
|
3 | export async function a_sume(fn, throws) {
|
4 | try {
|
5 | return await fn();
|
6 | }
|
7 | catch (e) {
|
8 | throw throws(e);
|
9 | }
|
10 | }
|
11 | export function s_sume(fn, throws) {
|
12 | try {
|
13 | return fn();
|
14 | }
|
15 | catch (e) {
|
16 | throw throws(e);
|
17 | }
|
18 | }
|
19 | export function filenameOutsideFabLocations(filename) {
|
20 | return filename !== '/server.js' && !filename.startsWith('/_assets/');
|
21 | }
|
22 | export function getContentType(pathname) {
|
23 | const mimeType = mime.lookup(pathname);
|
24 | return (mimeType && mime.contentType(mimeType)) || DEFAULT_MIME_TYPE;
|
25 | }
|
26 | export function getCacheHeaders(immutable) {
|
27 | return immutable ? IMMUTABLE_HEADERS : NON_IMMUTABLE_HEADERS;
|
28 | }
|
29 | export function matchPath(lookup_table, _pathname) {
|
30 | const pathname = decodeURIComponent(_pathname);
|
31 | return (lookup_table[pathname] ||
|
32 | lookup_table[pathname + '.html'] ||
|
33 | lookup_table[`${pathname}${pathname.endsWith('/') ? '' : '/'}index.html`]);
|
34 | }
|
35 | export const stripTrailingSlash = (str) => str.replace(/\/$/, '');
|
36 |
|
\ | No newline at end of file |