PassionateDeveloper
PassionateDeveloper

Reputation: 15138

Split React and WebAPI in 2 projects?

after stuck in Asp.Net MVC and JQuery for around 4 years I want to go further and switch to .net Core 2, WebAPI and React.

So I have learned through a bunch of howtos and tutorials but what makes me wonder is why every tutorial tells you to add the react just into the WebAPI Project in vs2017?

Isn't it a better way to make a project for WebAPI and a single new project for React (just a folder in the solution e.g. and work with vs code here?)

Why / why not?

Upvotes: 6

Views: 4654

Answers (3)

Nicolás Len
Nicolás Len

Reputation: 21

A change is coming on Visual Studio that solves this problem:

Starting in Visual Studio 2022 Preview 2, you can use the method described in this article to create ASP.NET Core Single Page Applications that

  • Put the client app in a separate project, outside from the ASP.NET Core project
  • Create the client project based on the framework CLI installed on your computer

Source: Tutorial: Create an ASP.NET Core app with React in Visual Studio

Upvotes: 1

Basilf
Basilf

Reputation: 461

For sure splitting them into 2 different projects.

API:

Use WebAPI on visual studio as a separate project, bind your project on a fixed port in IIS.

REACT:

Use ReactJS with VS CODE as a new project, and let it work with that localhost:PORT you defined on IIS.

When deploying to production, you can use a windows server to run BOTH of them on IIS. One different site as the API (then you can point api.DOMAIN.com on your domain) and another on the same IIS server that will run your client code (www.DOMAIN.com) or you can setup NODE to run it on windows, but then you'll need some more work to make it work for a production environment.

Personally I wouldn't do that and I would run the react app on Apache or NGINX. And if it's not a large scale website, you can just use Heroku for deployment.

Upvotes: 7

Marko
Marko

Reputation: 72222

I would separate into 2 separate projects. APIs are meant for re-use even if to start you will be building your API for a specific front-end.

Create 2 projects and repositories. They will also likely be deployed independently, your WebAPI will be hosted in a .NET environment whilst you can host your React app literally anywhere.

Upvotes: 9

Related Questions