[英]How to use Node -r flag inside npm scripts on Azure App Service
I am running a node site on an Azure App Service but it won't start with the following line in my package.json scripts.我在 Azure 应用服务上运行一个节点站点,但它不会以我的 package.json 脚本中的以下行开头。
"scripts": {
...
"serve": "node -r dotenv-azure/config dist/server.js",
...
},
The -r flag is required to preload environment variables using dotenv-azure, as per their own instructions... https://www.npmjs.com/package/dotenv-azure -r 标志需要使用 dotenv-azure 预加载环境变量,按照他们自己的说明... https://www.npmjs.com/package/dotenv-azure
it works absolutely fine on localhost (Windows), it loads the config before starting the server.它在本地主机(Windows)上工作得非常好,它在启动服务器之前加载配置。 On Azure App service (windows) however it fails to start the server and I get a 503 error after starting it.
在 Azure 应用程序服务(Windows)上,但是它无法启动服务器,启动后出现 503 错误。
I have tried switching on application logging but because it can't even start the server I get nothing in the logs.我尝试打开应用程序日志记录,但因为它甚至无法启动服务器,所以我在日志中什么也没有。
After add httpplatformhandler
in web.config
file, it works for me.在
web.config
文件中添加httpplatformhandler
后,它对我有用。 You can download my sample code from github .您可以从 github 下载我的示例代码。 You will find my
web.config
file.你会发现我的
web.config
文件。
1. Create a sample code. 1. 创建示例代码。
2. Create .env
file. 2. 创建
.env
文件。
3. Test result in local. 3. 本地测试结果。
4. Deploy by git. 4.通过git部署。
After deployed, it also has some error, we should add web.config
to solve it.部署后也有错误,需要添加
web.config
来解决。
After add web.config
file ( With httpplatformhandler
):添加
web.config
文件后(使用httpplatformhandler
):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.