D
D
Dmitry Belov2019-05-19 15:42:48
.NET
Dmitry Belov, 2019-05-19 15:42:48

How to run react app together .net core web api on same port?

Hello.
Wrote frontend using react create app, separate backend using visual studio .net core web api.
To launch the project, I need to separately launch the frontend, it launches at http://localhost:3000, and then the backend launches at localhost:3201/api/values ​​(this opens the browser at this address) and to get data I need to insert the address localhost:3201/api/values.
The questions are this:

  1. Is it possible to somehow shamanize, so that when the npm start command starts frontend and backend at once and on the same port, so that from frontend I can access api at localhost:3000/api/values ​​?
  2. And what would the backend not run in the browser, but for example in the console?

Structure:
Project start folder
5ce14ead2f39c566564416.png
app (frontend) (react create app)
5ce14ed2b4adc031549565.png
server (backend) (visual studio .net core web api)
5ce14f0df072b293070576.png

Thank you all in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Stolyarov, 2019-05-19
@buxin

so that when the npm start command starts frontend and backend at once and on the same port

Multiple processes cannot listen on the same port. What you need is that what gives frontend (webpack-dev-server in development or nginx in production) proxy requests along the /api path to another port (the process with the server)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question