Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
sites: revert using fallback origin
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Sep 23, 2024
1 parent 68c8fe1 commit 18cc2a5
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 129 deletions.
35 changes: 22 additions & 13 deletions platform/src/components/aws/analog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,7 @@ export class Analog extends Component implements Link.Linkable {
const outputPath = buildApp(parent, name, args, sitePath);
const preset = outputPath.apply((output) => {
const nitro = JSON.parse(
fs
.readFileSync(path.join(output, "dist/analog/nitro.json"))
.toString(),
fs.readFileSync(path.join(output, "dist/analog/nitro.json")).toString(),
);
if (!["aws-lambda"].includes(nitro.preset)) {
throw new VisibleError(
Expand Down Expand Up @@ -447,9 +445,19 @@ export class Analog extends Component implements Link.Linkable {
}

function loadBuildMetadata() {
return outputPath.apply(() => ({
assetsPath: path.join("dist/analog", "public"),
}));
return outputPath.apply((outputPath) => {
const assetsPath = path.join("dist/analog", "public");

return {
assetsPath,
// create 1 behaviour for each top level asset file/folder
staticRoutes: fs
.readdirSync(path.join(outputPath, assetsPath), {
withFileTypes: true,
})
.map((item) => (item.isDirectory() ? `${item.name}/*` : item.name)),
};
});
}

function buildPlan() {
Expand Down Expand Up @@ -504,13 +512,14 @@ export class Analog extends Component implements Link.Linkable {
cfFunction: "serverCfFunction",
origin: "server",
},
{
pattern: "*",
cacheType: "server",
cfFunction: "serverCfFunction",
origin: "fallthrough",
allowedMethods: ["GET", "HEAD", "OPTIONS"],
},
...buildMeta.staticRoutes.map(
(route) =>
({
cacheType: "static",
pattern: route,
origin: "s3",
}) as const,
),
],
});
});
Expand Down
15 changes: 9 additions & 6 deletions platform/src/components/aws/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,6 @@ export class Astro extends Component implements Link.Linkable {

plan.behaviors.push(
{
cacheType: "server",
cfFunction: "serverHostOnly",
origin: "regionalServer",
},
{
pattern: "*",
cacheType: "server",
cfFunction: "server",
origin: "fallthroughServer",
Expand All @@ -573,6 +567,15 @@ export class Astro extends Component implements Link.Linkable {
origin: "regionalServer",
allowedMethods: ["GET", "HEAD", "OPTIONS"],
},
...buildMeta.serverRoutes?.map(
(route) =>
({
cacheType: "server",
cfFunction: "serverHostOnly",
pattern: route,
origin: "regionalServer",
}) as const,
),
);
}

Expand Down
38 changes: 21 additions & 17 deletions platform/src/components/aws/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,19 @@ export class Nuxt extends Component implements Link.Linkable {
}

function loadBuildMetadata() {
return outputPath.apply(() => ({
assetsPath: path.join(".output", "public"),
}));
return outputPath.apply((outputPath) => {
const assetsPath = path.join(".output", "public");

return {
assetsPath,
// create 1 behaviour for each top level asset file/folder
staticRoutes: fs
.readdirSync(path.join(outputPath, assetsPath), {
withFileTypes: true,
})
.map((item) => (item.isDirectory() ? `${item.name}/*` : item.name)),
};
});
}

function buildPlan() {
Expand Down Expand Up @@ -475,13 +485,6 @@ export class Nuxt extends Component implements Link.Linkable {
],
},
},
fallthrough: {
group: {
primaryOriginName: "s3",
fallbackOriginName: "server",
fallbackStatusCodes: [403, 404],
},
},
},
behaviors: [
{
Expand All @@ -495,13 +498,14 @@ export class Nuxt extends Component implements Link.Linkable {
cfFunction: "serverCfFunction",
origin: "server",
},
{
pattern: "*",
cacheType: "server",
cfFunction: "serverCfFunction",
origin: "fallthrough",
allowedMethods: ["GET", "HEAD", "OPTIONS"],
},
...buildMeta.staticRoutes.map(
(route) =>
({
cacheType: "static",
pattern: route,
origin: "s3",
}) as const,
),
],
});
});
Expand Down
38 changes: 21 additions & 17 deletions platform/src/components/aws/solid-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,19 @@ export class SolidStart extends Component implements Link.Linkable {
}

function loadBuildMetadata() {
return outputPath.apply(() => ({
assetsPath: path.join(".output", "public"),
}));
return outputPath.apply((outputPath) => {
const assetsPath = path.join(".output", "public");

return {
assetsPath,
// create 1 behaviour for each top level asset file/folder
staticRoutes: fs
.readdirSync(path.join(outputPath, assetsPath), {
withFileTypes: true,
})
.map((item) => (item.isDirectory() ? `${item.name}/*` : item.name)),
};
});
}

function buildPlan() {
Expand Down Expand Up @@ -484,13 +494,6 @@ export class SolidStart extends Component implements Link.Linkable {
],
},
},
fallthrough: {
group: {
primaryOriginName: "s3",
fallbackOriginName: "server",
fallbackStatusCodes: [403, 404],
},
},
},
behaviors: [
{
Expand All @@ -504,13 +507,14 @@ export class SolidStart extends Component implements Link.Linkable {
cfFunction: "serverCfFunction",
origin: "server",
},
{
pattern: "*",
cacheType: "server",
cfFunction: "serverCfFunction",
origin: "fallthrough",
allowedMethods: ["GET", "HEAD", "OPTIONS"],
},
...buildMeta.staticRoutes.map(
(route) =>
({
cacheType: "static",
pattern: route,
origin: "s3",
}) as const,
),
],
});
},
Expand Down
Loading

0 comments on commit 18cc2a5

Please sign in to comment.