title: Requests.js:7 GET http://localhost:3001/testing net::ERR_CONNECTION_REFUSED. Apache Server, Express, React App, Fetching , Hosting
body: <p>I have searched and there is a ton of questions just like this with the full code with the issue, but when reading the comments and posts, there are suggestions and they say they tried something and it worked but don't post the actual changes they made explicitly. I will actually do this.</p>
  <p>So this is me not knowing how to setup the communications between a React App and server when publishing. So in testing and on the machine that is hosting... the fetch() works great. When I try it on another laptop or my phone I get  <code>Requests.js:7 GET http://localhost:3001/testing net::ERR_CONNECTION_REFUSED.</code></p>
  <p>I setup the server using Apache and a raspberrypi for testing.</p>
  <p>From what I read I think it might have to do with localhost on another computer isn't local. How do I get this to work?</p>
  <p>Here is an example link: <a href="http://uptoptest.hopto.org/" rel="nofollow noreferrer">http://uptoptest.hopto.org/</a></p>
  <p>Here is the code for the example link: <a href="https://github.com/monochromaticmau/testingLiveWebsite" rel="nofollow noreferrer">https://github.com/monochromaticmau/testingLiveWebsite</a></p>
  <p>Should I provide the folder of the apache stuff?  I think this is a simple thing that i'm just missing how to properly make the server.js available  the right way.</p>
  <p>Requests.js</p>
  <pre><code>const Data = {};
  const baseUrl = 'http://localhost:3001'
  
  Data.getTest = () =&gt; {
    let url  = `${baseUrl}/testing`;
    return fetch(url).then(response =&gt; {
      if (!response.ok) {
        return new Promise(resolve =&gt; resolve([]));
      }
      return response.json().then(jsonResponse =&gt; {
        return jsonResponse.test
      });
    });
  };
  </code></pre>
  <p>server.js</p>
  <pre><code>const express = require('express')
  const app = express()
  const cors = require('cors')
  
  
  const PORT = process.env.PORT || 3001
  
  app.use(express.static('public')); //'public' folder contains js, css, images
  
  app.use(cors());
  app.use(express.json());
  
  app.use((req,res,next)=&gt;{
      console.log(`Request!!`)
      console.log(req.originalUrl)
      console.log(req.path)
      
      //res.setHeader('Access-Control-Allow-Origin', '*')
      next();
  })
  
  app.get('/testing', (req,res,next)=&gt;{
      console.log('TEST REQUEST')
      res.send({test: &quot;Data blah blah&quot;})
  })
  
  
  
  
  app.listen(PORT, ()=&gt;{
      console.log(`Listening on Port ${PORT}`)
  })
  
  //Used for Testing Server
  module.exports = app;
  </code></pre>
  <p>You guys are pretty smart people here... please don't hack into my little pi, if you know how.</p>