我是否需要 node.js (express) 才能将 Angular 应用程序部署到 Heroku?

时间:2021-01-17 17:37:10

标签: javascript node.js angular heroku deployment

我能否在 Heroku 上仅使用 node.js/express 运行我的 Angular 应用程序(使用 ng build --prod 构建)?

据我所知,生产环境中的 Angular 不需要 node.js 服务器,但可以仅使用生成的静态文件(和一些配置)运行。您可以在 node.js 服务器/express 上运行它,但这不是强制性的。

到目前为止,在我在 Google 上找到的关于在 Heroku 上部署 Angular 应用程序的大部分教程中,说明总是在 Angular 应用程序中设置一个 server.js 文件,并在 package.json 那里设置通常类似于带有 postinstall 命令的 heroku-postbuildng build --prod 脚本。

我想,我混淆了一些概念,或者对 Heroku 上的 Angular 应用程序部署存在普遍误解。

1 个答案:

答案 0 :(得分:0)

不,您还可以创建一个简单的 http 服务器并托管应用程序。但是,这不会帮助您了解您的应用程序是如何成为服务器的。 Express-node 服务器重量轻,可以帮助您定义路由。

您还可以重定向此服务器上的任何 https 请求。

# Calculating total Amount of Cores
Write-Output "Calculating the total Cores of VMs ..."
try {
    $TotalCores = $null
    $Location = "westeurope"
    $Cores = $null
    $TotalVMs = (Get-AzVM -Status | Where-Object { $_.ProvisioningState -eq "Succeeded" }) | Sort-Object -Property Name

    foreach ($VM in $TotalVMs) {
        Write-Output "Checking $($Vm.Name) ..."
        $VMSize = (Get-AzVM -Name $VM.Name).HardwareProfile.VmSize
        $Cores = (Get-AzVMSize -location $Location | Where-Object { $_.name -eq $VMSize }).NumberOfCores
        $TotalCores += $Cores
    }
    Write-Output "Wow! Found '$TotalCores' Cores ..."
}
catch {
    $ErrorMsg = "[ERROR] while calculating the total CPU Cores: $($_.Exception.Message)!"
    Write-Error -Message $ErrorMsg
}

您还可以使用 Docker 在 Heroku 上运行 Angular 应用程序。

相关问题