App.js GET Request to Server.js

Hey Y’all,
I’m trying to send a get request from App.js to server.js, but the html file is not being sent. The console.log( returns HTML text, so it looks like it’s connecting to my server, but its not redirecting to the board.html

handleSubmit = async e => {
    const response =
      await axios.get("/b/general/")

This is the server route I’m trying to call to:

  .get(function (req, res) {
    res.sendFile(process.cwd() + '/client/public/board.html');

Cheers! :+1:

Axios does a request and gets the data. in this case: a page.

You never told the browser what to do with this data.

Since you are trying to “get a page and render it”, just do that the way browsers are designed: by navigating to it.

Dont use axios.get
but push ur browser location to it.
you can do this with an a-tag.

or, if you want to do it with javascript:

1 Like

Hey there,
Thanks for the reply. So when I use an a-tag, I can <a href="/b/general/">Board</a>, but nothing is rendered because that route is running on a different port on my server.js. I would have to use <a href="http://localhost:5000/b/general/">Board</a> for it to work locally, but I don’t see how that would work on a production build. Would proxies help with that?

Thank you again for the feedback. So this is what I’ve come up with so far:

handleSubmit = e => {
    window.location.assign("http://localhost:5000" + this.state.get)

But I’m still having the same problem with the ports. How will this work on a production build if I want to switch between ports?

Some options are suggested here. No beauties, but it might be the best ull get.
Second answer seems best on this link.

1 Like

Thank you so much! I will try this tomorrow. This looks like what I need. I will post here if it works :+1: :pray:

For those who have a similar issue, here is what I did:

handleSubmit = e => {
    window.location.assign(window.location.protocol + "//" + window.location.hostname + ":5000" + this.state.get)

Cheers :+1: