【问题标题】:Deploy angular 6 app and Web API in same Azure Web app在同一个 Azure Web 应用中部署 Angular 6 应用和 Web API
【发布时间】:2019-05-17 12:43:39
【问题描述】:

我遵循this 策略在同一个 Azure Web 应用中部署 Angular 应用和 Web api。

我在 VS 2017 中使用 VSCode 和 Web Api 进行 Angular 应用程序开发。所以它不是像 VS 2017 中的 Angular 应用程序模板中的完整应用程序

我用

部署了 web api
services.AddSpaStaticFiles(configuration =>
{
    configuration.RootPath = "ClientApp/dist";
});

app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";
});

已将 Angular 应用程序的构建版本复制到 Azure Web 应用程序上的 ClientApp/dist 文件夹。将 azure 应用的 WEBSITE_NODE_DEFAULT_VERSION 设置为 10.14.1,那里可用。

但是当我浏览网站时,我在浏览器控制台中收到错误 -

SyntaxError: expected expression, got '<'[Learn More] runtime.js:1
SyntaxError: expected expression, got '<'[Learn More] polyfills.js:1
SyntaxError: expected expression, got '<'[Learn More] styles.js:1
SyntaxError: expected expression, got '<'[Learn More] scripts.js:1
SyntaxError: expected expression, got '<'[Learn More] vendor.js:1
SyntaxError: expected expression, got '<'[Learn More] main.js:1 

我看到了,所有请求都获取 index.html 而不是实际的 .js 文件。

似乎带有节点的角度应用程序没有启动。

【问题讨论】:

    标签: node.js angular azure asp.net-core azure-web-app-service


    【解决方案1】:

    我建议您将 Angular 应用程序移至 Azure 存储静态网站 服务。部署起来会非常简单,而且资源使用率(I/O、CPU、内存等)也应该更低。见:

    更新

    查看Separating production and development HTTP URLs using environment.ts file in Angular,了解如何传递您的 API 的 URL,并为不同的环境管理不同的 URL。

    更新 2

    您也可以关注this guide 并检查您的启动代码中是否缺少任何内容。

    希望对你有帮助!

    【讨论】:

    • 是的,这听起来很合理。但我不确定如何将该静态应用程序连接到我的 web api,因为 proxy.conf.js 在生产中不可用,并且我的 api 端点将不同于 angular 端点。
    • 这行得通,但它也有它自己的问题。我想知道为什么 ClientApp/dist 没有提供 Angular 服务。如果我使用 VS 模板创建一个示例 Angular 应用程序并进行部署,它会做同样的事情并且可以工作。如果做同样的事情,我无法确定为什么它不起作用。
    • 我建议你看看this guide,它描述了如何在不使用内置VS模板的情况下创建上述组合,看看你的启动代码中是否缺少某些东西。
    • 非常感谢@itay,这就是答案!
    • 更新了我的答案以包含上述评论的内容。请将其标记为该问题的答案。谢谢!并乐于提供帮助!
    猜你喜欢
    • 2020-02-26
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 2022-01-06
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    相关资源
    最近更新 更多