fix : reload pages 404 error

This commit is contained in:
GuillaumeSD
2025-05-17 03:47:04 +02:00
parent 653f3f1de4
commit e7e4b737e9
2 changed files with 29 additions and 1 deletions

View File

@@ -13,18 +13,27 @@ import {
Source, Source,
} from "aws-cdk-lib/aws-s3-deployment"; } from "aws-cdk-lib/aws-s3-deployment";
import path from "path"; import path from "path";
import { renameSync } from "fs";
import { ARecord, HostedZone, RecordTarget } from "aws-cdk-lib/aws-route53"; import { ARecord, HostedZone, RecordTarget } from "aws-cdk-lib/aws-route53";
import { CloudFrontTarget } from "aws-cdk-lib/aws-route53-targets"; import { CloudFrontTarget } from "aws-cdk-lib/aws-route53-targets";
import { DnsValidatedCertificate } from "aws-cdk-lib/aws-certificatemanager"; import { DnsValidatedCertificate } from "aws-cdk-lib/aws-certificatemanager";
interface AppStackProps extends cdk.StackProps { interface AppStackProps extends cdk.StackProps {
domainName: string; domainName: string;
pagePaths: string[];
} }
export class AppStack extends cdk.Stack { export class AppStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: AppStackProps) { constructor(scope: Construct, id: string, props: AppStackProps) {
super(scope, id, props); super(scope, id, props);
const { domainName } = props; const { domainName, pagePaths } = props;
for (const pageName of pagePaths) {
renameSync(
path.resolve(__dirname, `../out/${pageName}.html`),
path.resolve(__dirname, `../out/${pageName}`)
);
}
const mainBucket = new Bucket(this, "Bucket", { const mainBucket = new Bucket(this, "Bucket", {
accessControl: BucketAccessControl.PRIVATE, accessControl: BucketAccessControl.PRIVATE,
@@ -47,6 +56,7 @@ export class AppStack extends cdk.Stack {
exclude: ["engines"], exclude: ["engines"],
}), }),
], ],
exclude: pagePaths,
memoryLimit: 512, memoryLimit: 512,
cacheControl: [ cacheControl: [
CacheControl.setPublic(), CacheControl.setPublic(),
@@ -54,6 +64,23 @@ export class AppStack extends cdk.Stack {
], ],
}); });
new BucketDeployment(this, "BucketPagesDeployment", {
destinationBucket: mainBucket,
sources: [
Source.asset(path.resolve(__dirname, "../out"), {
exclude: ["engines"],
}),
],
exclude: ["*"],
include: pagePaths,
memoryLimit: 512,
cacheControl: [
CacheControl.setPublic(),
CacheControl.maxAge(cdk.Duration.hours(1)),
],
contentType: "text/html",
});
new BucketDeployment(this, "BucketEnginesDeployment", { new BucketDeployment(this, "BucketEnginesDeployment", {
destinationBucket: enginesBucket, destinationBucket: enginesBucket,
destinationKeyPrefix: "engines", destinationKeyPrefix: "engines",

View File

@@ -6,4 +6,5 @@ const app = new cdk.App();
new AppStack(app, "FreechessWebapp", { new AppStack(app, "FreechessWebapp", {
env: { region: "eu-west-3", account: process.env.CDK_DEFAULT_ACCOUNT }, env: { region: "eu-west-3", account: process.env.CDK_DEFAULT_ACCOUNT },
domainName: "chesskit.org", domainName: "chesskit.org",
pagePaths: ["play", "database"],
}); });