D
D
Demigodd2019-09-23 19:57:44
Node.js
Demigodd, 2019-09-23 19:57:44

What is the correct way to deploy an application to Heroku?

I can’t figure out how to correctly specify the links, that is, if I opened the application locally, then the Express server was on localhost:3003 and the React front was on localhost:3000 .
It's all logical. During the request through axios, the main link was indicated , that is, the request is made to the backend. Same with Socket.IO during connecta
axios.defaults.baseURL = http://localhost:3003

io(http://localhost:3003, { transports: ['websocket'] });

Now, for deployment, as I understand it, you need an already assembled React APP that the server will send to the user, and then the user will execute requests without reloading the pages, etc.
To do this, the server has the following code.
app.use('/', express.static(path.join(__dirname, '../build')));

app.get('/*', (req: any, res: any) => {
  res.sendFile(path.resolve(__dirname, '../build', 'index.html'));
});

Now, when I call npm start , I execute react-scripts build and then I start the server itself.
And this is where hemorrhoids begin.
In theory, I need to specify 3 links.
1) For an axios request.
2) To connect Socket.IO.
3) PUBLIC_URL which is written in public/index.html, for manifest.json and favicon.ico.
How to properly arrange all this in its place?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vadimMalovaniy, 2019-09-24
@Demigodd

At the front, write insteadlocalhost:3003window.location.host

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question