Skip to content

Commit

Permalink
simplify code in adapter-node (#2056)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Aug 1, 2021
1 parent 3e30a1b commit 2f4418f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 2 additions & 20 deletions packages/adapter-node/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
}
},
Expand Down

0 comments on commit 2f4418f

Please sign in to comment.