From 2f4418f5f2a5629bc8de958726e82e0f0d1bfded Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 1 Aug 2021 00:05:05 -0400 Subject: [PATCH] simplify code in adapter-node (#2056) --- packages/adapter-node/index.js | 2 +- packages/adapter-node/src/server.js | 22 ++-------------------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index 1628751aae64..83762f86533e 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -73,7 +73,7 @@ export default function ({ target: 'node12', inject: [join(files, 'shims.js')], define: { - esbuild_app_dir: '"' + config.kit.appDir + '"' + APP_DIR: `"/${config.kit.appDir}/"` } }; const buildOptions = esbuildConfig ? await esbuildConfig(defaultOptions) : defaultOptions; diff --git a/packages/adapter-node/src/server.js b/packages/adapter-node/src/server.js index ac22dc253827..4dc6c69aa209 100644 --- a/packages/adapter-node/src/server.js +++ b/packages/adapter-node/src/server.js @@ -16,25 +16,6 @@ const paths = { }; export function createServer({ render }) { - const immutable_path = (pathname) => { - // eslint-disable-next-line no-undef - let app_dir = esbuild_app_dir; - - // hard to tell when app_dir is mixed with static - if (app_dir === '/') { - return false; - } - - if (app_dir.startsWith('/')) { - app_dir = app_dir.slice(1); - } - if (app_dir.endsWith('/')) { - app_dir = app_dir.slice(0, -1); - } - - return pathname.startsWith(`/${app_dir}/`); - }; - const prerendered_handler = fs.existsSync(paths.prerendered) ? sirv(paths.prerendered, { etag: true, @@ -47,7 +28,8 @@ export function createServer({ render }) { const assets_handler = fs.existsSync(paths.assets) ? sirv(paths.assets, { setHeaders: (res, pathname, stats) => { - if (immutable_path(pathname)) { + // eslint-disable-next-line no-undef + if (pathname.startsWith(APP_DIR)) { res.setHeader('cache-control', 'public, max-age=31536000, immutable'); } },