Link to chapter - https://serverless-stack.com/chapters/manage-environments-in-create-react-app.html
Looking for a little clarity on this section. Are we supposed to run these build commands here? Itâs not clear on whether you are giving an example of what to run later, or we are actually supposed to be running the build commands for dev and prod during this section.
REACT_APP_STAGE=prod npm run build
Good point. Iâll edit it to make it clear. Itâs just an example. We use this command later in our build process.
My API tests pass, but when I try to set the configuration for dev or prod on the client with the new values Iâm getting 500 status codes.
GET https://api.colemars.com/dev/notes 500
The previous values still work correctly.
Passing API test:
gateway-cli-test
âusername=âadmin@example.comâ
âpassword=âPassw0rd!â
âuser-pool-id=âus-east-1_MRRQ40XM7â
âapp-client-id=â69tve4h4s4tjnhd93052v8h3taâ
âcognito-region=âus-east-1â
âidentity-pool-id=âus-east-1:7982caeb-8a8d-4411-8358-e12f5be8a03aâ
âinvoke-url=âhttps://api.colemars.com/devâ
âapi-gateway-region=âus-east-1â
âpath-template=â/notesâ
âmethod=âPOSTâ
âbody=â{âcontentâ:âhello worldâ,âattachmentâ:âhello.jpgâ}â
Failing client access:
const dev = {
s3: {
REGION: "us-east-1",
BUCKET: "notes-app-2-api-dev-attachmentsbucket-gebtjvlj0ile"
},
apiGateway: {
REGION: "us-east-1",
URL: "https://api.colemars.com/dev"
},
cognito: {
REGION: "us-east-1",
USER_POOL_ID: "us-east-1_MRRQ40XM7",
APP_CLIENT_ID: "69tve4h4s4tjnhd93052v8h3ta",
IDENTITY_POOL_ID: "us-east-1:7982caeb-8a8d-4411-8358-e12f5be8a03a"
}
};
Any idea?
A 500 error means that itâs getting through to your Lambda functions and then failing. I would enable logging and try seeing if that gives something.
What is the most secure way to hide environment vars within a React app? I donât really want to show my S3, Api Gateway and Cognito credentials if someone was to inspect my minified source code.
Thanks for any info.
So we arenât putting out our credentials here. They are only the idâs for the resources involved. And these resources cannot be accessed without authentication.