Skip to content

[preview 5] url of api not accessible in react app when deployed on Azure #3917

Answered by colinnuk
JorenSchelkens asked this question in Q&A
Discussion options

You must be logged in to vote

I dont think this is related to Aspire. It looks to me like you are building a transpiled SPA and serving it with nginx.

When you're running the website via npm, the npm webserver you are using adds the environment variables inside the React application as part of process.env. But now that you are serving the JS files directly from 'disk' - the environment variables aren't available to the JS code as process.env doesn't exist.

One option is to write a JS file which contains the values you need, and then reference those as needed in your React code. When you're running the app via npm you would use process.env values, and when it's deployed with nginx you'll be reading them from the config…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@JorenSchelkens
Comment options

Answer selected by JorenSchelkens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
3 participants
Converted from issue

This discussion was converted from issue #3909 on April 24, 2024 14:31.