Skip to content

Commit

Permalink
Merge branch 'main' into feature/flesh-in-appbar
Browse files Browse the repository at this point in the history
  • Loading branch information
hxtree authored Feb 17, 2024
2 parents e2afb22 + 1b021b3 commit 8d74fa5
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 94 deletions.
8 changes: 4 additions & 4 deletions clients/admin-client/src/components/ArchetypeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export default function ArchetypeSelect() {
const [archetypeData, setArchetypeData] = useState<object>({});
const [isLoading, setLoading] = useState<boolean>(true);

const parentDomainName = import.meta.env.VITE_PARENT_DOMAIN_NAME ?? 'sandbox.nekosgate.com';

useEffect(() => {
const archetypesFetch = async () => {
setLoading(true);

try {
const res = await axios.get(
'https://nx7uv2rfy4.execute-api.us-east-2.amazonaws.com/default/v1/character/archetypes',
);
const res = await axios.get(`https://api.${parentDomainName}/character-sheets/archetypes`);

setArchetypes(res.data);
} catch (err) {
Expand All @@ -42,7 +42,7 @@ export default function ArchetypeSelect() {
setLoading(true);
try {
const res = await axios.get(
`https://nx7uv2rfy4.execute-api.us-east-2.amazonaws.com/default/v1/character/archetypes/${archetypeId}`,
`https://api.${parentDomainName}/character-sheets/archetypes/${archetypeId}`,
);

setArchetypeData(res.data);
Expand Down
4 changes: 3 additions & 1 deletion clients/admin-client/src/components/DiceAnalyzer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const DiceAnalyzer = (props: DiceAnalyzerProps) => {

const analytics = new Analytics('DiceAnalyzer');

const parentDomainName = import.meta.env.VITE_PARENT_DOMAIN_NAME ?? 'sandbox.nekosgate.com';

const clear = async () => {
setData([]);
setRunningTotal(0);
Expand All @@ -43,7 +45,7 @@ export const DiceAnalyzer = (props: DiceAnalyzerProps) => {

// Make a request for a user with a given ID
const res = await axios.post(
'https://nx7uv2rfy4.execute-api.us-east-2.amazonaws.com/default/v1/luck-by-dice/dice-roll',
`https://api.${parentDomainName}/dice/dice-roll`,
{
notation: notation,
luck: luck,
Expand Down
138 changes: 96 additions & 42 deletions clients/admin-client/stacks/admin-client.stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import { Construct } from 'constructs';
import * as cdk from 'aws-cdk-lib';
import * as ssm from 'aws-cdk-lib/aws-ssm';
import { RemovalPolicy, StackProps } from 'aws-cdk-lib';
import { Bucket, BucketAccessControl } from 'aws-cdk-lib/aws-s3';
import {
Bucket,
RedirectProtocol,
ObjectOwnership,
BucketAccessControl,
} from 'aws-cdk-lib/aws-s3';
import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment';
import {
Distribution,
CloudFrontWebDistribution,
OriginAccessIdentity,
ResponseHeadersPolicy,
ViewerProtocolPolicy,
} from 'aws-cdk-lib/aws-cloudfront';
import { S3Origin } from 'aws-cdk-lib/aws-cloudfront-origins';
import * as route53 from 'aws-cdk-lib/aws-route53';
import * as targets from 'aws-cdk-lib/aws-route53-targets';
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
import * as route53 from 'aws-cdk-lib/aws-route53';

export class AdminClientStack extends cdk.Stack {
public parentDomainName: string;
Expand All @@ -22,14 +26,64 @@ export class AdminClientStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

// DNS

// fetch parameters from SSM Parameter Store
this.parentDomainName = ssm.StringParameter.fromStringParameterAttributes(
this,
`${id}-ssm-domain-name`,
{
parameterName: 'DOMAIN_NAME',
},
).stringValue;

// Retrieve parameters from SSM Parameter Store
this.hostedZoneId = ssm.StringParameter.fromStringParameterAttributes(
this,
`${id}-hosted-zone-id`,
{
parameterName: 'my-domains-hosted-zone-id',
},
).stringValue;

const subdomainName = 'admin';

const domainName = `${subdomainName}.${this.parentDomainName}`;

// s3 bucket
const awsAccountId = cdk.Stack.of(this).account;
const stageName = process.env.STAGE_NAME ?? 'default';

const redirects = [
{ from: 'authentication/', to: 'features/authentication/' },
];

const bucket = new Bucket(this, `${stageName}-admin-client`, {
bucketName: `${awsAccountId}-${stageName}-admin-client-bucket`,
accessControl: BucketAccessControl.PRIVATE,
websiteIndexDocument: 'index.html',
websiteErrorDocument: '404.html',
publicReadAccess: true,
blockPublicAccess: {
blockPublicAcls: false,
blockPublicPolicy: false,
ignorePublicAcls: false,
restrictPublicBuckets: false,
},
objectOwnership: ObjectOwnership.OBJECT_WRITER,
accessControl: BucketAccessControl.PUBLIC_READ,
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
websiteRoutingRules: redirects.map(({ from, to }) => ({
condition: {
keyPrefixEquals: from,
},
httpRedirectCode: '301',
hostName: domainName,
protocol: RedirectProtocol.HTTPS,
replaceKey: {
withKey: to,
},
})),
});

const originAccessIdentity = new OriginAccessIdentity(
Expand All @@ -52,46 +106,46 @@ export class AdminClientStack extends cdk.Stack {
this.acmCertificateArn,
);

// DNS

// fetch parameters from SSM Parameter Store
this.parentDomainName = ssm.StringParameter.fromStringParameterAttributes(
const cloudFrontDistribution = new CloudFrontWebDistribution(
this,
`${id}-ssm-domain-name`,
`${id}-admin-client-distribution`,
{
parameterName: 'DOMAIN_NAME',
defaultRootObject: 'index.html',
originConfigs: [
{
s3OriginSource: {
s3BucketSource: bucket,
},
behaviors: [
{
isDefaultBehavior: true,
defaultTtl: cdk.Duration.seconds(0),
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
},
],
},
],
errorConfigurations: [
{
errorCode: 404,
responseCode: 200,
responsePagePath: '/index.html', // Redirect to index.html for all 404 errors
errorCachingMinTtl: 60,
},
],
viewerCertificate: {
aliases: [domainName],
props: {
acmCertificateArn: certificate.certificateArn,
sslSupportMethod: 'sni-only',
},
},
},
).stringValue;

// Retrieve parameters from SSM Parameter Store
this.hostedZoneId = ssm.StringParameter.fromStringParameterAttributes(
this,
`${id}-hosted-zone-id`,
{
parameterName: 'my-domains-hosted-zone-id',
},
).stringValue;

const subdomainName = 'admin';

const domainName = `${subdomainName}.${this.parentDomainName}`;

// cloudfront distribution
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const cloudFrontDistribution = new Distribution(this, 'Distribution', {
defaultRootObject: 'index.html',
defaultBehavior: {
origin: new S3Origin(bucket, { originAccessIdentity }),
// todo lock down CORS later
responseHeadersPolicy:
ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT,
},
domainNames: [domainName],
certificate,
});
);
cloudFrontDistribution.applyRemovalPolicy(RemovalPolicy.DESTROY);

// bucket resource
new BucketDeployment(this, 'BucketDeployment', {
new BucketDeployment(this, `${id}-bucket-deployment`, {
destinationBucket: bucket,
sources: [Source.asset('./dist')],
retainOnDelete: false,
Expand All @@ -116,7 +170,7 @@ export class AdminClientStack extends cdk.Stack {
});

new cdk.CfnOutput(this, 'Cloud Front Distribution', {
value: cloudFrontDistribution.domainName,
value: cloudFrontDistribution.distributionDomainName,
});

new cdk.CfnOutput(this, 'Domain Name', {
Expand Down
4 changes: 2 additions & 2 deletions clients/design-system/bin/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { App } from 'aws-cdk-lib';
import { DesignSystemStack } from '../stacks/design-system.stack';
import { MainStack } from '../stacks/main.stack';

const app = new App();
new DesignSystemStack(app, 'DesignSystemStack');
new MainStack(app, 'DesignSystem');
Loading

0 comments on commit 8d74fa5

Please sign in to comment.