将 .NET Core 后端添加到 Aurelia 项目
Adding a .NET Core back-end to an Aurelia project
我的前端在 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?
别担心。你是在正确的方向。如果您查看 ASP.NET 核心团队的 source code of SPA,您会发现他们也在做与您相同的事情。当有传入的相关消息时,ASP.NET 核心服务器会将其简单地代理到开发服务器。
例如,the default project template for creating ASP.NET Core application with Angular使用angular-cli
在一个端口上启动前端开发服务器,这与ASP.NET核心监听的不同。
附带说明一下,"front end" 项目仅在开发时运行。无需关心性能。
我的前端在 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?
别担心。你是在正确的方向。如果您查看 ASP.NET 核心团队的 source code of SPA,您会发现他们也在做与您相同的事情。当有传入的相关消息时,ASP.NET 核心服务器会将其简单地代理到开发服务器。
例如,the default project template for creating ASP.NET Core application with Angular使用angular-cli
在一个端口上启动前端开发服务器,这与ASP.NET核心监听的不同。
附带说明一下,"front end" 项目仅在开发时运行。无需关心性能。