diff --git a/packages/ssr/src/firebase/serve-storefront.ts b/packages/ssr/src/firebase/serve-storefront.ts index 25b4abe09..6e0077ad5 100644 --- a/packages/ssr/src/firebase/serve-storefront.ts +++ b/packages/ssr/src/firebase/serve-storefront.ts @@ -2,14 +2,9 @@ import type { Request, Response } from 'firebase-functions'; import { join as joinPath } from 'path'; import { readFile } from 'fs/promises'; -const { - STOREFRONT_BASE_DIR, - STOREFRONT_LONG_CACHE, -} = process.env; - +const { STOREFRONT_BASE_DIR } = process.env; const baseDir = STOREFRONT_BASE_DIR || process.cwd(); const clientRoot = new URL(joinPath(baseDir, 'dist/client/'), import.meta.url); -const isLongCache = String(STOREFRONT_LONG_CACHE).toLowerCase() === 'true'; export default (req: Request, res: Response) => { const url = req.url.replace(/\?.*$/, '').replace(/\.html$/, ''); @@ -24,33 +19,16 @@ export default (req: Request, res: Response) => { ); }; - const redirect = (toUrl: string, status = 302) => { - let sMaxAge = status === 301 ? 360 : 12; - if (isLongCache) { - sMaxAge *= 10; - } - let cacheControl = `public, max-age=30, s-maxage=${sMaxAge}`; - if (status === 302) { - cacheControl += ', proxy-revalidate'; - } - setStatusAndCache(status, cacheControl) - .set('Location', toUrl).end(); - }; - - const fallback = (status = 404) => { - const is404 = status === 404; - if (is404 && url.slice(-1) === '/') { - redirect(url.slice(0, -1)); - } else if (url !== `/${status}` && (/\/[^/.]+$/.test(url) || /\.x?html$/.test(url))) { - setStatusAndCache(status, `public, max-age=${(isLongCache ? 120 : 30)}`) + const fallback = (err: any, status = 500) => { + if (url !== '/fallback' && (/\/[^/.]+$/.test(url) || /\.x?html$/.test(url))) { + setStatusAndCache(status, 'public, max-age=120') .send('
' - + `` - + ''); + + '` + + `${err.toString()}