Skip to content

Commit

Permalink
Updating local server with AWS backend
Browse files Browse the repository at this point in the history
  • Loading branch information
bstascavage committed Jul 18, 2023
1 parent 3ee36b6 commit 80c4aac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ Once the prerequisites are installed locally, follow these steps:

1. To enter the container to run development commands, run `./anvilw bash`. Once inside the container, you can start the development server via `task serve`.

#### Running locally against a cloud backend

> NOTE: This assumes you have access to the AWS account with the StatsCollide database
1. Make sure you pull the AWS Amplify environment you want (either `main` or `develop`) via the command: `amplify pull --envName develop`. When asked `Do you plan on modifying this backend?`, select **Yes**. (NOTE: This will update a bunch of files locally. Do not commit these changes in git unless you know what you are doing)

1. Run `task npm-start REACT_APP_LOCAL_BACKEND=false`. Instead of deploying the front-end app locally with a local mock DB, this will deploy your front-end app locally but connect it to the Graphql endpoint in AWS for your given environment. **Make sure this is for read-only operations, as to not overwrite data in the production database**

### Available development commands

In addition to regular `npm` commands, a handful of macros have been set up for common development commands. These commands can be run via `task <command>` when in the container via `./anvilw bash`. The following macros have been configured:
Expand Down
2 changes: 2 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ tasks:
desc: Starts npm dev server
cmds:
- REACT_APP_LOCAL_BACKEND={{.REACT_APP_LOCAL_BACKEND}} npm start
vars:
REACT_APP_LOCAL_BACKEND: '{{ coalesce .REACT_APP_LOCAL_BACKEND "true"}}'

mock-api:
desc: Starts a local mock api server
Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import CONFIG from "./config";
// Amplify auto-generates aws-exports but sets it to the host IP and not localhost if you use mock
// This breaks in docker because docker networking is crazy.
// This logic allows us to toggle it
if (process.env.REACT_APP_LOCAL_BACKEND) {
if (process.env.REACT_APP_LOCAL_BACKEND === true) {
var localAwsExports = {
...awsExports,
aws_appsync_graphqlEndpoint: "http://localhost:20002/graphql",
Expand Down

0 comments on commit 80c4aac

Please sign in to comment.