-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rehanvandermerwe
committed
Feb 22, 2024
1 parent
6894434
commit c309617
Showing
8 changed files
with
143 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Test PR | ||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- edited | ||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm run build-src | ||
- run: npm run validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Frontend</title> | ||
</head> | ||
<body> | ||
|
||
<h1>Frontend</h1> | ||
|
||
<h2>Test the api by navigating to <a href="/api/">/api/</a></h2> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import * as cdk from "aws-cdk-lib"; | ||
import { Construct } from "constructs"; | ||
import * as cloudfront from "aws-cdk-lib/aws-cloudfront"; | ||
import { CachePolicy } from "aws-cdk-lib/aws-cloudfront"; | ||
import * as origins from "aws-cdk-lib/aws-cloudfront-origins"; | ||
import * as s3 from "aws-cdk-lib/aws-s3"; | ||
import * as s3deploy from "aws-cdk-lib/aws-s3-deployment"; | ||
import * as path from "path"; | ||
import { EnvironmentConfig } from "@config/index"; | ||
|
||
export type FrontendProps = { | ||
apiOrigin: string; | ||
}; | ||
|
||
export class Frontend extends cdk.Stack { | ||
constructor( | ||
scope: Construct, | ||
id: string, | ||
stackProps: cdk.StackProps, | ||
config: EnvironmentConfig, | ||
props: FrontendProps | ||
) { | ||
super(scope, id, stackProps); | ||
|
||
function name(name: string): string { | ||
return id + "-" + name; | ||
} | ||
|
||
const frontendBucket = new s3.Bucket(this, name("web-bucket"), { | ||
bucketName: name("web-bucket"), | ||
autoDeleteObjects: true, | ||
removalPolicy: cdk.RemovalPolicy.DESTROY, | ||
}); | ||
|
||
const frontendDist = new cloudfront.Distribution(this, name("web-dist"), { | ||
comment: name("web-dist"), | ||
defaultBehavior: { | ||
origin: new origins.S3Origin(frontendBucket), | ||
compress: true, | ||
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, | ||
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, | ||
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED, | ||
}, | ||
additionalBehaviors: { | ||
"/api/*": { | ||
origin: new origins.HttpOrigin(props.apiOrigin, { | ||
readTimeout: cdk.Duration.seconds(60), | ||
}), | ||
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, | ||
compress: false, | ||
cachePolicy: CachePolicy.CACHING_DISABLED, | ||
}, | ||
}, | ||
defaultRootObject: "index.html", | ||
}); | ||
|
||
new s3deploy.BucketDeployment(this, name("deploy-with-invalidation"), { | ||
sources: [s3deploy.Source.asset(path.join(__dirname, "dist/frontend"))], | ||
destinationBucket: frontendBucket, | ||
distribution: frontendDist, | ||
distributionPaths: ["/*"], | ||
}); | ||
|
||
new cdk.CfnOutput(this, name("CloudFrontURL"), { | ||
description: "Frontend Url", | ||
value: cdk.Fn.join("", ["https://", frontendDist.distributionDomainName]), | ||
}); | ||
new cdk.CfnOutput(this, name("APIURL"), { | ||
description: "Api Url", | ||
value: cdk.Fn.join("", ["https://", frontendDist.distributionDomainName, "/api/"]), | ||
}); | ||
} | ||
} | ||
|
||
export default Frontend; |