Skip to content

Commit 022a747

Browse files
authored
Preview adjustments (#5)
* address some tsc errors * add cdk stack for frontend deployment * add commands revolving around frontend to makefile * update README --------- Co-authored-by: lukqw <[email protected]>
1 parent 80a11fa commit 022a747

9 files changed

+64
-9
lines changed

Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ deploy:
2727
start:
2828
localstack start -d
2929

30+
## export configs for web app
31+
prepare-frontend-local:
32+
yarn prepare:frontend-local
33+
34+
build-frontend:
35+
yarn build:frontend
36+
37+
bootstrap-frontend:
38+
yarn cdklocal bootstrap --app="node dist/aws-sdk-js-notes-app-frontend.js";
39+
40+
deploy-frontend:
41+
yarn cdklocal deploy --app="node dist/aws-sdk-js-notes-app-frontend.js";
42+
3043
## Stop the Running LocalStack container
3144
stop:
3245
@echo

README.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,21 @@ arn:aws:cloudformation:us-east-1:000000000000:stack/aws-sdk-js-notes-app/ebb3238
118118
To configure the frontend to use the deployed infrastructure, run the following command:
119119

120120
```shell
121-
yarn prepare:frontend-local
121+
make prepare-frontend-local
122122
```
123123

124124
It will update the `packages/frontend/src/config.json` file with the deployed infrastructure's output values.
125125

126+
### Deploying the frontend
127+
128+
```shell
129+
make build-frontend
130+
make bootstrap-frontend
131+
make deploy-frontend
132+
```
133+
134+
Alternatively you can start the frontend locally with below steps:
135+
126136
### Starting the frontend
127137

128138
To start the frontend, run the following command:
@@ -131,8 +141,6 @@ To start the frontend, run the following command:
131141
yarn start:frontend
132142
```
133143

134-
Alternatively, you can build the frontend and deploy it to S3 to access it from a browser.
135-
136144
### Testing the web application
137145

138146
To test the web application, open the URL you see in the output of the `yarn start:frontend` command in your browser. You will see the following page:
@@ -162,5 +170,4 @@ The sample application is based on a public [AWS sample app](https://github.com/
162170
## Contributing
163171

164172
We appreciate your interest in contributing to our project and are always looking for new ways to improve the developer experience. We welcome feedback, bug reports, and even feature ideas from the community.
165-
Please refer to the [contributing file](CONTRIBUTING.md) for more details on how to get started.
166-
173+
Please refer to the [contributing file](CONTRIBUTING.md) for more details on how to get started.

packages/frontend/src/content/CreateNote.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const CreateNote = (props: RouteComponentProps) => {
3232
body: JSON.stringify({ attachment, content: noteContent }),
3333
});
3434
navigate("/");
35-
} catch (error) {
35+
} catch (error: any) {
3636
setErrorMsg(`${error.toString()} - ${createNoteURL} - ${noteContent}`);
3737
} finally {
3838
setIsLoading(false);

packages/frontend/src/content/DeleteNoteButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const DeleteNoteButton = (props: { noteId: string; attachment?: string }) => {
2424
method: "DELETE",
2525
});
2626
navigate("/");
27-
} catch (error) {
27+
} catch (error: any) {
2828
setErrorMsg(`${error.toString()} - ${deleteNoteURL} - ${noteId}`);
2929
} finally {
3030
setIsDeleting(false);

packages/frontend/src/content/ListNotes.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ListNotes = (props: RouteComponentProps) => {
2424
const response = await fetch(fetchURL);
2525
const data = await response.json();
2626
setNotes(data);
27-
} catch (error) {
27+
} catch (error: any) {
2828
setErrorMsg(`${error.toString()} - ${fetchURL}`);
2929
} finally {
3030
setIsLoading(false);

packages/frontend/src/content/SaveNoteButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const SaveNoteButton = (props: { noteId: string; noteContent: string }) => {
2121
body: JSON.stringify({ content: noteContent }),
2222
});
2323
navigate("/");
24-
} catch (error) {
24+
} catch (error: any) {
2525
console.log(error);
2626
setErrorMsg(`${error.toString()} - ${updateNoteURL} - ${noteContent}`);
2727
} finally {

packages/frontend/src/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if (typeof (window as any).process === "undefined") {
1616
}
1717

1818
const container = document.getElementById("root");
19+
// @ts-ignore
1920
const root = createRoot(container);
2021
root.render(
2122
<div className="container" style={{ height: "100vh" }}>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {
2+
Stack,
3+
StackProps,
4+
CfnOutput,
5+
aws_s3 as s3,
6+
aws_s3_deployment,
7+
} from "aws-cdk-lib";
8+
import { Construct } from "constructs";
9+
10+
export class AwsSdkJsNotesAppFrontendStack extends Stack {
11+
constructor(scope: Construct, id: string, props?: StackProps) {
12+
super(scope, id, props);
13+
14+
const websiteBucket = new s3.Bucket(this, "WebsiteBucket", {
15+
bucketName: "notes-app-frontend",
16+
websiteIndexDocument: "index.html",
17+
websiteErrorDocument: "index.html",
18+
});
19+
20+
new aws_s3_deployment.BucketDeployment(this, "DeployWebsite", {
21+
sources: [aws_s3_deployment.Source.asset("../frontend/dist")],
22+
destinationBucket: websiteBucket,
23+
});
24+
25+
new CfnOutput(this, "FrontendBucketWebsite", {
26+
value: `http://${websiteBucket.bucketName}.s3-website.localhost.localstack.cloud:4566/`,
27+
});
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { App } from "aws-cdk-lib";
2+
import { AwsSdkJsNotesAppFrontendStack } from "./aws-sdk-js-notes-app-frontend-stack";
3+
4+
const app = new App();
5+
new AwsSdkJsNotesAppFrontendStack(app, "aws-sdk-js-notes-app-frontend");

0 commit comments

Comments
 (0)