Skip to content

Commit

Permalink
simplify and hopefully fix adapter-node and adapter-netlify
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Oct 12, 2022
1 parent 65ec1b7 commit 25e5024
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions packages/adapter-cloudflare-workers/files/entry.js
Expand Up @@ -6,7 +6,7 @@ const static_asset_manifest = JSON.parse(static_asset_manifest_json);

const server = new Server(manifest);

const app_path = `/${manifest.appPath}/`;
const prefix = `/${manifest.appDir}/`;

export default {
/**
Expand All @@ -20,12 +20,12 @@ export default {
const url = new URL(req.url);

// static assets
if (url.pathname.startsWith(app_path)) {
if (url.pathname.startsWith(prefix)) {
/** @type {Response} */
const res = await get_asset_from_kv(req, env, context);
if (is_error(res.status)) return res;

const cache_control = url.pathname.startsWith(app_path + 'immutable/')
const cache_control = url.pathname.startsWith(prefix + 'immutable/')
? 'public, immutable, max-age=31536000'
: 'no-cache';

Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-cloudflare/src/worker.js
Expand Up @@ -4,7 +4,7 @@ import * as Cache from 'worktop/cfw.cache';

const server = new Server(manifest);

const app_path = `/${manifest.appPath}/`;
const prefix = `/${manifest.appDir}/`;

/** @type {import('worktop/cfw').Module.Worker<{ ASSETS: import('worktop/cfw.durable').Durable.Object }>} */
const worker = {
Expand All @@ -18,11 +18,11 @@ const worker = {
let { pathname } = new URL(req.url);

// static assets
if (pathname.startsWith(app_path)) {
if (pathname.startsWith(prefix)) {
res = await env.ASSETS.fetch(req);
if (!res.ok) return res;

const cache_control = pathname.startsWith(app_path + 'immutable/')
const cache_control = pathname.startsWith(prefix + 'immutable/')
? 'public, immutable, max-age=31536000'
: 'no-cache';

Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/index.js
Expand Up @@ -63,7 +63,7 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
builder.copy('_headers', headers_file);
appendFileSync(
headers_file,
`\n\n/${builder.getAppPath()}/immutable/*\n cache-control: public\n cache-control: immutable\n cache-control: max-age=31536000\n`
`\n\n/${builder.getAppDirectory()}/immutable/*\n cache-control: public\n cache-control: immutable\n cache-control: max-age=31536000\n`
);

if (edge) {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/index.js
Expand Up @@ -118,7 +118,7 @@ export default function ({ external = [], edge, split } = {}) {
...redirects[builder.config.kit.trailingSlash],
...prerendered_redirects,
{
src: `/${builder.getAppPath()}/.+`,
src: `/${builder.getAppDirectory()}/.+`,
headers: {
'cache-control': 'public, immutable, max-age=31536000'
}
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/adapt/builder.js
Expand Up @@ -128,8 +128,8 @@ export function create_builder({ config, build_data, routes, prerendered, log })
return config.kit.files.assets;
},

getAppPath() {
return build_data.app_path;
getAppDirectory() {
return build_data.app_dir;
},

writeClient(dest) {
Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/core/generate_manifest/index.js
Expand Up @@ -45,7 +45,6 @@ export function generate_manifest({ build_data, relative_path, routes, format =
/** @type {import('types').SSRManifest} */
return `{
appDir: ${s(build_data.app_dir)},
appPath: ${s(build_data.app_path)},
assets: new Set(${s(assets)}),
mimeTypes: ${s(get_mime_lookup(build_data.manifest_data))},
_: {
Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/exports/vite/dev/index.js
Expand Up @@ -59,7 +59,6 @@ export async function dev(vite, vite_config, svelte_config) {

manifest = {
appDir: svelte_config.kit.appDir,
appPath: svelte_config.kit.appDir,
assets: new Set(manifest_data.assets.map((asset) => asset.file)),
mimeTypes: get_mime_lookup(manifest_data),
_: {
Expand Down
3 changes: 1 addition & 2 deletions packages/kit/src/exports/vite/index.js
Expand Up @@ -395,8 +395,7 @@ function kit() {

/** @type {import('types').BuildData} */
build_data = {
app_dir: svelte_config.kit.appDir,
app_path: `${svelte_config.kit.paths.base.slice(1)}${
app_dir: `${svelte_config.kit.paths.base.slice(1)}${
svelte_config.kit.paths.base ? '/' : ''
}${svelte_config.kit.appDir}`,
manifest_data,
Expand Down
5 changes: 2 additions & 3 deletions packages/kit/types/index.d.ts
Expand Up @@ -85,8 +85,8 @@ export interface Builder {
getClientDirectory(): string;
getServerDirectory(): string;
getStaticDirectory(): string;
/** The application path including any configured base path */
getAppPath(): string;
/** The application directory including any configured base path */
getAppDirectory(): string;

/**
* @param dest the destination folder to which files should be copied
Expand Down Expand Up @@ -381,7 +381,6 @@ export interface ServerInitOptions {

export interface SSRManifest {
appDir: string;
appPath: string;
assets: Set<string>;
mimeTypes: Record<string, string>;

Expand Down
1 change: 0 additions & 1 deletion packages/kit/types/internal.d.ts
Expand Up @@ -47,7 +47,6 @@ export interface Asset {

export interface BuildData {
app_dir: string;
app_path: string;
manifest_data: ManifestData;
service_worker: string | null;
client: {
Expand Down

0 comments on commit 25e5024

Please sign in to comment.