问题
I have a setup similar to the one in this tutorial. How can I render JSON alone (no HTML) without having to specify the port number for the route specified in index.js
? Within my own setup, I can view JSON by visiting https://socialmaya.com/u/real but can't get an actual JSON response unless I visit http://socialmaya.com:5000/actors/real, which is what's being called by React.
Here is my code which is an attempt to implement an ActivityPub API for a social network built using the MERN stack. My Nginx configuration can be found here.
回答1:
Rewriting the URL before passing it upstream within Nginx solved my problem:
location / {
rewrite ^/u/(.*)$ /actors/$1 last;
proxy_pass http://localhost:5000;
}
来源:https://stackoverflow.com/questions/61160329/how-can-i-return-a-valid-json-response-with-react-router-and-an-express-backend