0

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.

6
  • 2
    I guess you want to render the data of that json. I'm I right? If that is what you want you need to do a petition to that route with axios, ajax, fetch or something like this and it will return the json data. Commented Apr 11, 2020 at 20:04
  • I need to render the JSON itself without any HTML whatsoever encapsulating it. You can see the difference in what I mean if you click to View Page Source for socialmaya.com/u/real and socialmaya.com:5000/actors/real. Commented Apr 11, 2020 at 20:14
  • So I need to render the JSON as plaintext essentially (without having to specify a port number for the backend) but it seems like this might be impossible if I'm using React-Router at all in my project. Commented Apr 11, 2020 at 20:17
  • I mean, the content of both webs are the same, only thing changing is the font. Commented Apr 11, 2020 at 20:21
  • I think that Mastodon or any other social network using ActivityPub needs to receive the response as valid or pure JSON. As far as I know, if the JSON is being rendered through a React component instead of being returned in a plaintext response, other servers or machines won't be able to read the data successfully. Commented Apr 11, 2020 at 20:26

1 Answer 1

0

Rewriting the URL before passing it upstream within Nginx solved my problem:

location / {
    rewrite ^/u/(.*)$ /actors/$1 last;
    proxy_pass http://localhost:5000;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a better way of doing this that doesn't require adding an Nginx rewrite for every route I define with Express that I want to be able to access without specifying a port number, that returns valid JSON, and is able to be reached by the browser or something like curl?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.