简体   繁体   English

nestjs 到 azure windows 应用服务 - web.config 设置

[英]nestjs to azure windows app service - web.config settings

I've been trying to deploy my nestjs api to azure since yesterday and have not been successful.从昨天开始,我一直在尝试将我的nestjs api 部署到 azure 并且没有成功。 At first I was trying to push it to a linux cloud service plan and was able to deploy it from vs code, see in the azure logs that the app was successfully started, but it would not return any data from my endpoints and after some digging, I kept seeing some container failures.起初我试图将它推送到 linux 云服务计划,并且能够从 vs 代码部署它,在 azure 日志中看到应用程序已成功启动,但它不会从我的端点返回任何数据,经过一些挖掘,我一直看到一些容器故障。 I tried troubleshooting that for a while then decided I would try setting it up on a windows app service instead.我尝试了一段时间的故障排除,然后决定尝试将其设置在 windows 应用服务上。

Following this guide: https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-nodejs , I pushed my nestjs app up to an azure app service on windows and again, it did not work.遵循本指南: https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-nodejs ,我将我的nestjs应用程序推到Z0F454260ED1525B5上的azure应用程序服务再次,它没有工作。 I pulled down the repo in that article to compare it to mine and they have the entry point in the web.config for the nodejs app pointing to index.js.我拉下那篇文章中的存储库以将其与我的进行比较,它们在 web.config 中有指向 index.js 的 nodejs 应用程序的入口点。 That index.js doesn't exist in my nestjs app and I did some research and found out that the entry point for a nestjs app after everything is compiled is main.js.我的nestjs应用程序中不存在那个index.js,我做了一些研究,发现编译完所有内容后nestjs应用程序的入口点是main.js。 There is another difference in that sample project and my nestjs app in that the nestjs app's main.js file appears to be in a dist folder, rather than at the root of the wwwroot path.该示例项目和我的nestjs 应用程序的另一个区别在于nestjs 应用程序的main.js 文件似乎位于dist 文件夹中,而不是位于wwwroot 路径的根目录中。

My nestjs app obviously didn't contain a web.config out of the box so I created one using the hello world repo's as an example.我的nestjs应用程序显然不包含开箱即用的web.config,所以我以hello world repo为例创建了一个。 I updated the iisnode path to dist/main.js and the rewrite path as well to the same path/file since that's the only thing I can think to do.我将 iisnode 路径更新为 dist/main.js 并将重写路径更新为相同的路径/文件,因为这是我唯一能想到的。

The only other wildcard is the node version number that I'm changing in azure for the WEBSITE_NODE_DEFAULT_VERSION application setting...I'm not sure what that should be for my nestjs app.唯一的其他通配符是我在 azure 中为 WEBSITE_NODE_DEFAULT_VERSION 应用程序设置更改的节点版本号......我不确定我的 nestjs 应用程序应该是什么。 My current local version is 12.16.2 but when I change the version to that on azure, it doesn't work.我当前的本地版本是 12.16.2,但是当我将版本更改为 azure 上的版本时,它不起作用。

I'm not sure what else to try here - I'd be fine trying to go back to linux if I could sort out the docker container issue but that seemed like a dead end.我不确定在这里还能尝试什么 - 如果我可以解决 docker 容器问题,我可以尝试将 go 回到 linux,但这似乎是一个死胡同。 I think I'll likely have more luck continuing down the windows route if I can just get this web.config / version thing to work.我想如果我能让这个 web.config / version 工作正常,我可能会有更多的运气继续沿着 windows 路线前进。

Is main.js in the dist folder where I should be pointing my web.config? main.js 在我应该指向我的 web.config 的 dist 文件夹中吗? Is there a max version limit on azure? azure 有最大版本限制吗? Is there anything else I might be missing?还有什么我可能会丢失的吗?

EDIT: After turning on streaming logs - I'm now seeing this exception编辑:打开流式日志后 - 我现在看到这个异常

SyntaxError: Use of const in strict mode. SyntaxError:在严格模式下使用 const。 at Module._compile (module.js:434:25) at Object..js (module.js:464:10) at Module.load (module.js:353:31) at Function._load (module.js:311:12) at Module.require (module.js:359:17) at require (module.js:375:17) at Object.在 Module._compile (module.js:434:25) 在 Object..js (module.js:464:10) 在 Module.load (module.js:353:31) 在 Function._load (module.js:311) :12) 在 Module.require (module.js:359:17) 在 require (module.js:375:17) 在 Object。 (D:\Program Files (x86)\iisnode\interceptor.js:459:1) at Module._compile (module.js:446:26) at Object..js (module.js:464:10) at Module.load (module.js:353:31) (D:\Program Files (x86)\iisnode\interceptor.js:459:1) 在 Module._compile (module.js:446:26) 在 Object..js (module.js:464:10) 在模块。加载(module.js:353:31)

after some googling, I've found that exception was common with older versions of node (< 4).经过一番谷歌搜索,我发现旧版本的节点(<4)很常见异常。 I'm well beyond that version and have azure set to a version well beyond that as well.我远远超出了该版本,并且将 azure 设置为远远超出该版本的版本。

I have read your two posts about nestjs deployment.我已经阅读了您关于nestjs 部署的两篇文章。

Now I think whatever platform you use, it will not succeed.现在我认为无论你使用什么平台,它都不会成功。 Because azure support us basic environment for web apps.因为 azure 支持我们 web 应用程序的基本环境。 Although your app is based on nodejs, when you run npm run start , you actually run nest start .尽管您的应用程序基于 nodejs,但当您运行npm run start ,您实际上运行的是nest start The basic environment should not support npm i -g @ nestjs/cli .基础环境应该不支持npm i -g @ nestjs/cli So I suggest you use docker to create the image and then deploy.所以我建议你使用 docker 创建镜像然后部署。

I got it sorted out with the help of a friend.我在朋友的帮助下解决了这个问题。 Running this in the azure cli got things sorted out using the linux setup.在 azure cli 中运行它可以使用 linux 设置解决问题。

az webapp config set --resource-group myResourceGroup --name myAppServiceName --startup-file "npm run start:prod"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Azure 应用服务 (Linux) 上运行的 Node/Next/React 应用是否需要 web.config 文件? - Is the web.config file required for a Node/Next/React App running on Azure App Service (Linux)? Azure App Service(Windows)配置变量 - Azure App Service (Windows) Config Variable 如何使用 azure + IISNode + express 为 React 应用程序构建 web.config - How To Build a web.config for a react app using azure + IISNode + express 如何为MEAN应用程序的Azure部署定义web.config文件? - How to define a web.config file for Azure deployment for a MEAN application? 在Azure中为SVG和字体表达NodeJS web.config - Express NodeJS web.config in Azure for SVG & Fonts 如何通过部署为node.js应用程序设置azure-web-app-service应用程序设置 - How to set azure-web-app-service application settings for node.js app via deployment 如何将 Dockerized(NestJS 应用程序)部署到云服务提供商,例如 Amazon Web Services (AWS)、Microsoft Azure、Google Cloud - How to Deploying a Dockerized ( NestJS app ) to Cloud Service Provider like Amazon Web Services (AWS), Microsoft Azure, Google Cloud WEB SOCKET CONFIG 未显示在 AZURE WEB 应用程序中 - WEB SOCKET CONFIG NOT SHOW IN AZURE WEB APP 无法在web.config / Azure WebApp中使用“ max-old-space”参数 - Cannot use “max-old-space” parameter in web.config/Azure WebApp 如何部署Nestjs App(在Azure上)? - How to deploy Nestjs App (on Azure)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM