Frank
📢 UpdateIn v0.33.0, we added the
ReactStaticSite
construct. It extends the StaticSite
with out of the box configuration for React SPAs.
More importantly, you can now 👉 reference your resources in your React app 👈.
For example, you can configure a React environment variable REACT_APP_API_URL
and set it to the Api endpoint url
new ReactStaticSite(this, "ReactSite", {
path: "path/to/react-app",
environment: {
REACT_APP_API_URL: api.url
}
});
And refer to it in your React code like this
// App.js
console.log(process.env.REACT_APP_API_URL);
Read more about using React environment variables here - https://docs.serverless-stack.com/constructs/ReactStaticSitethdxr
07/15/2021, 1:25 PMJay
Nick Laffey
07/15/2021, 9:06 PMNick Laffey
07/15/2021, 9:07 PMthdxr
07/15/2021, 9:21 PMthdxr
07/15/2021, 9:22 PMNick Laffey
07/15/2021, 9:25 PMEnvironment variables must start with.REACT_APP_
Jay
Nick Laffey
07/15/2021, 9:36 PMJay
Jay