nestjs to azure windows app service - web.config settings

好久不见. 提交于 2020-07-22 18:51:06

问题


I've been trying to deploy my nestjs api to azure since yesterday and have not been successful. 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. I tried troubleshooting that for a while then decided I would try setting it up on a windows app service instead.

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. 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. 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. 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.

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. 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.

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. My current local version is 12.16.2 but when I change the version to that on azure, it doesn't work.

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. 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.

Is main.js in the dist folder where I should be pointing my web.config? Is there a max version limit on 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. 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. (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)

after some googling, I've found that exception was common with older versions of node (< 4). I'm well beyond that version and have azure set to a version well beyond that as well.


回答1:


I have read your two posts about nestjs deployment.

Now I think whatever platform you use, it will not succeed. Because azure support us basic environment for web apps. Although your app is based on nodejs, when you run npm run start, you actually run nest start. The basic environment should not support npm i -g @ nestjs/cli. So I suggest you use docker to create the image and then deploy.




回答2:


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.

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


来源:https://stackoverflow.com/questions/61232654/nestjs-to-azure-windows-app-service-web-config-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!