Skip to content

Commit 2e7b268

Browse files
committed
Switch to use .env for configure frontend
1 parent b1db53c commit 2e7b268

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

deploy.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ aws cloudformation deploy \
6363
--parameter-overrides ServerSourceS3Key=$SOURCE_ZIP
6464

6565
printf "\n>>> Saving the CloudFormation output to a JSON file...\n"
66-
aws cloudformation describe-stacks --stack-name GameroomStack | jq ".Stacks[0].Outputs | map({(.OutputKey): .OutputValue}) | add" > frontend/src/api_endpoints.json
66+
67+
aws cloudformation describe-stacks \
68+
--stack-name GameroomStack \
69+
| jq -r '(.Stacks[0].Outputs)[] | "REACT_APP_\(.OutputKey | gsub("(?<a>[a-z])(?<b>[A-Z])"; "\(.a)_\(.b)") | ascii_upcase)=\(.OutputValue)"' \
70+
> frontend/.env
6771

6872
printf "\n>>> The output of CloudFormation is:\n"
69-
cat frontend/src/api_endpoints.json
73+
cat frontend/.env
7074

7175
# Enter /frontend
7276
pushd frontend

deploy/cloudformation-template.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,3 @@ Outputs:
662662
Value: !GetAtt ApiGatewayApiHttp.ApiEndpoint
663663
WebSocketEndpointUrl:
664664
Value: !Join ["/", [!GetAtt ApiGatewayApiWebSocket.ApiEndpoint, staging]]
665-
S3BucketFrontEndName:
666-
Value: !Ref S3BucketFrontEnd
667-
CloudFrontDomainName:
668-
Value: !GetAtt CloudFrontDistribution.DomainName

frontend/src/apis/Api.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Delta, Snapshot } from "shared-models";
22

3-
import endpoints from "../api_endpoints.json";
3+
import { HTTP_ENDPOINT_URL } from "../constants";
44

55
export async function createRoom(): Promise<
66
| {
@@ -12,7 +12,7 @@ export async function createRoom(): Promise<
1212
roomData: { roomId: string };
1313
}
1414
> {
15-
const response = await fetch(`${endpoints.HttpEndpointUrl}/rooms`, {
15+
const response = await fetch(`${HTTP_ENDPOINT_URL}/rooms`, {
1616
method: "POST",
1717
mode: "cors",
1818
});
@@ -38,7 +38,7 @@ export async function getRoomSnapshot(
3838
roomId: string
3939
): Promise<GetRoomSnapsotResponse> {
4040
const response = await fetch(
41-
`${endpoints.HttpEndpointUrl}/rooms/${roomId}/snapshot`,
41+
`${HTTP_ENDPOINT_URL}/rooms/${roomId}/snapshot`,
4242
{
4343
method: "GET",
4444
mode: "cors",
@@ -64,7 +64,7 @@ export async function getRoomDeltas(
6464
toSeq: number
6565
): Promise<Delta[]> {
6666
const response = await fetch(
67-
`${endpoints.HttpEndpointUrl}/rooms/${roomId}/deltas?fromSeq=${fromSeq}&toSeq=${toSeq}`,
67+
`${HTTP_ENDPOINT_URL}/rooms/${roomId}/deltas?fromSeq=${fromSeq}&toSeq=${toSeq}`,
6868
{
6969
method: "GET",
7070
mode: "cors",

frontend/src/apis/WebSocketManager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
isLeaderSelectionMessage,
2020
} from "shared-models";
2121

22-
import endpoints from "../api_endpoints.json";
22+
import { WEB_SOCKET_ENDPOINT_URL } from "../constants";
2323
import Logger from "../utils/Logger";
2424

2525
class WebSocketManager {
@@ -39,7 +39,7 @@ class WebSocketManager {
3939
// Cannot provide specific type for WebSocketSubject because the provided
4040
// type definition force incoming and outgoing message to be the same type.
4141
this.webSocketSubject = webSocket<any>({
42-
url: endpoints.WebSocketEndpointUrl,
42+
url: WEB_SOCKET_ENDPOINT_URL,
4343
openObserver: {
4444
next: () => {
4545
this.logger.debug("^^^ connection open");

frontend/src/constants.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const HTTP_ENDPOINT_URL = process.env
2+
.REACT_APP_HTTP_ENDPOINT_URL as string;
3+
4+
export const WEB_SOCKET_ENDPOINT_URL = process.env
5+
.REACT_APP_WEB_SOCKET_ENDPOINT_URL as string;

0 commit comments

Comments
 (0)