将React和WebAPI拆分为2个项目? [英] Split React and WebAPI in 2 projects?

查看:49
本文介绍了将React和WebAPI拆分为2个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Asp.Net MVC和JQuery大约4年之后,我想走得更远,切换到.net Core 2,WebAPI和React.

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.

因此,我已经学习了一堆howto和教程,但令我感到奇怪的是,为什么每个教程都告诉您将React添加到vs2017中的WebAPI项目中?

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?

为WebAPI创建一个项目和为React创建一个新项目不是更好的方法吗(只是解决方案中的一个文件夹,例如,在这里使用vs代码?)

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?)

为什么/为什么不呢?

推荐答案

确保将它们分为2个不同的项目.

For sure splitting them into 2 different projects.

API:

将Visual Studio上的WebAPI用作单独的项目,将项目绑定到IIS中的固定端口上.

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

反应:

使用带有VS CODE的ReactJS作为新项目,并使其与您在IIS上定义的localhost:PORT一起使用.

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

部署到生产环境时,可以使用Windows服务器在IIS上同时运行它们.一个与API不同的站点(然后您可以将api.DOMAIN.com指向您的域),另一个在同一IIS服务器上运行客户端代码(www.DOMAIN.com),也可以将NODE设置为在Windows上运行,但是您需要做更多的工作才能使其在生产环境中正常工作.

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.

我个人不会这样做,而是在Apache或NGINX上运行react应用.如果它不是大型网站,则可以使用Heroku进行部署.

这篇关于将React和WebAPI拆分为2个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆