forked from Scottish-Tech-Army/learning-play-audit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update split the CDK stacks into back and front end
Update the building docs
- Loading branch information
Donal Stewart
committed
Jan 10, 2021
1 parent
7ed98d5
commit 18a2db9
Showing
22 changed files
with
265 additions
and
23 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,58 @@ | ||
const cdk = require("@aws-cdk/core"); | ||
const { Bucket } = require("@aws-cdk/aws-s3"); | ||
const cloudfront = require("@aws-cdk/aws-cloudfront"); | ||
const origins = require("@aws-cdk/aws-cloudfront-origins"); | ||
const s3deploy = require("@aws-cdk/aws-s3-deployment"); | ||
|
||
class CdkFrontendStack extends cdk.Stack { | ||
/** | ||
* | ||
* @param {cdk.Construct} scope | ||
* @param {string} id | ||
* @param {cdk.StackProps=} props | ||
*/ | ||
constructor(scope, stackId, props) { | ||
super(scope, stackId, props); | ||
|
||
// React website hosting - survey client | ||
addHostedWebsite(this, "SurveyWebClient", "../surveyclient/build"); | ||
|
||
// React website hosting - admin client | ||
addHostedWebsite(this, "AdminWebClient", "../adminclient/build"); | ||
|
||
function addHostedWebsite(scope, name, pathToWebsiteContents) { | ||
const BUCKET_NAME = name; | ||
const DISTRIBUTION_NAME = name + "Distribution"; | ||
const DEPLOY_NAME = name + "DeployWithInvalidation"; | ||
|
||
const bucket = new Bucket(scope, BUCKET_NAME, {}); | ||
|
||
const distribution = new cloudfront.Distribution( | ||
scope, | ||
DISTRIBUTION_NAME, | ||
{ | ||
defaultBehavior: { | ||
origin: new origins.S3Origin(bucket), | ||
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, | ||
viewerProtocolPolicy: | ||
cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, | ||
}, | ||
defaultRootObject: "index.html", | ||
} | ||
); | ||
|
||
new s3deploy.BucketDeployment(scope, DEPLOY_NAME, { | ||
sources: [s3deploy.Source.asset(pathToWebsiteContents)], | ||
destinationBucket: bucket, | ||
distribution, | ||
}); | ||
|
||
new cdk.CfnOutput(scope, name + " URL", { | ||
value: "https://" + distribution.domainName, | ||
description: "External URL for " + name + " website", | ||
}); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { CdkFrontendStack }; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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