I have a json file in my react project public folder like this
public
|
|___Data
| test.json
In my .tsx file I’m referencing the file like this
fetch(`${process.env.PUBLIC_URL}/Data/test.json`,
{
headers : {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then(response => response)
This works fine in development and when building and serving the app locally (npm run build). But when I try deploy to my Azure web app app service, the site throws a 404 error for that file.
I can also see the file in the Kudu debug console so I know it's getting deployed with the project.
Printing process.env.PUBLIC_URL
to console yields an empty string. Do I need to set this value to something using environment variables? Is there something else that I’m missing with my app service configuration?
I've looked at other similar questions, namely this one and the solution did not work for me either.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…