.net - 将 .NET Core 后端添加到 Aurelia 项目

标签 .net asp.net-core aurelia

我的前端位于 Aurelia,我正在尝试添加 .NET Core 后端。我的后端应该向前端发送一些数据,并接收前端提交的数据。我尝试了以下方法:

mkdir app
cd app
dotnet new webapi
au new --here

这工作正常,但后端正在监听端口 5000,而我的前端正在监听端口 8080。这是添加 .NET Core 后端的正确方法吗?同时拥有前端和后端运行在不同的端口上?

最佳答案

Is this the right way to add a .NET Core back-end

如果您想为 Aurelia 添加新的 ASP.NET Core 项目,则无需创建自己的工作流程。 您不必创建 ASP.NET Core 项目

只需使用au new(不使用dotnet new webapi):

    PS aurelia-app-hello> au new helloworld --here
    No Aurelia project found.
                          _ _          ____ _     ___
      __ _ _   _ _ __ ___| (_) __ _   / ___| |   |_ _|
     / _` | | | | '__/ _ \ | |/ _` | | |   | |    | |
    | (_| | |_| | | |  __/ | | (_| | | |___| |___ | |
     \__,_|\__,_|_|  \___|_|_|\__,_|  \____|_____|___|


    Which module loader / bundler would you like to use?

    1. Webpack (Default)
       A powerful and popular bundler for JavaScript
    2. CLI's built-in bundler with RequireJS
       RequireJS is a mature and stable module loader for JavaScript.
    3. CLI's built-in bundler with SystemJS
       SystemJS is Dynamic ES module loader, the most versatile module loader for JavaScript

    [Webpack]>

    What platform are you targeting?

    1. Web (Default)
       The default web platform setup.
    2. ASP.NET Core
       A powerful, patterns-based way to build dynamic websites with .NET.

    [Web]> 2

选择第二个选项au-cli将为您创建一个ASP.NET Core项目。它还会自动设置所有配置。

is it good practice to have both your front and back-end running on different ports?

别担心。你的方向是正确的。如果你查看source code of SPA通过 ASP.NET Core 团队,你会发现他们也在做和你一样的事情。当有传入的相关消息时,ASP.NET Core 服务器将简单地将其代理到开发服务器。

例如,the default project template for creating ASP.NET Core application with Angular使用 angular-cli 在端口上启动前端开发服务器,这与 ASP.NET Core 监听的端口不同。

顺便说一句,“前端”项目仅在开发时运行。无需关心性能。

关于.net - 将 .NET Core 后端添加到 Aurelia 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53710963/

相关文章:

c# - Mono WebClient 编码问题

asp.net-core - 为什么需要设置 "UseContentRoot(AppContext.BaseDirectory) in ASP.NET Core MVC"?

c# - .NET Core 配置的环境变量与构建配置

Aurelia - 没有由computeFrom 装饰器引用的嵌套数组的ModifyCollectionObserver?

c# - Azure Functions 和 IHealthCheck

c# - Aspose 或电子表格设备

asp.net - 新的 dotnet core 项目无法恢复

Aurelia 路由 : Append Views into Tabbed Interface

c# - 在 .NET 中创建 CD/DVD ISO 镜像

c# - Blazor 错误 400,ReasonPhrase 错误请求版本 : 1. 1 System.Net.Http.BrowserHttpHandler