我正在开发一个带有ASP.NET核心后端的完整堆栈web应用程序,它为REST & GraphQL API提供服务。Visual中的.NET核心应用程序的结构如下:
Backend.API: the API portion of the project that contains all the controllers and GraphQL query/mutation definitions that the front-end application consumes.
Backend.Core: the portion of the back-end that defines all the user & application models used by the Backend.Data portion.
Backend.Data: interacts with the database and defines all the repositories that the Backend.API portion uses when returning data for GraphQL queries, etc.后端.NET核心app由前端ReactJS应用程序使用,该应用程序完全独立于C#项目(作为单独的ReactJS应用程序创建)。
我不想使用ReactJS ASP.NET核心模板,因为我希望在前端和后端之间保持关注点的分离,这样的模板就会变得模糊。到目前为止,我已经允许前端ReactJS应用程序使用后端ASP.NET核心API,方法是提供后端启动的本地主机URL (即ReactJS应用程序在localhost:3000上启动,并从localhost上的API端点获取:5437,其中后端是由Visual启动的)。然而,当我想要部署网站时,这两个部分之间的这种分离是不可行的--我需要将前端项目和后端项目结合起来,以便它们在相同的URL下运行。
因此,这就提出了一个问题:将我的独立前端ReactJS应用程序与我的后端ASP.NET Core合并以便它们在一个URL下运行的最佳方法是什么?
发布于 2019-06-15 18:28:31
如果我在你的位置,我会这么做的:
wwwroot文件夹中index.html页面
:
App.Use (context,next) => {context();var path = context.Request.Path.Value;if (!path.StartsWith("/api") & !Path.HasExtension(path)) { context.Request.Path = "/index.html";等待next();});1. Be sure you have the middleware for default files and static files included in the pipeline:app.UseDefaultFiles(); app.UseStaticFiles();
https://stackoverflow.com/questions/56607931
复制相似问题