简体   繁体   English

如何在 Azure 应用服务上的 npm 脚本中使用 Node -r 标志

[英]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文件。

Test Steps:测试步骤:

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.

相关问题 如何修复将node.js部署到无法通过npm安装的azure应用程序服务? - How can I fix deployment of node.js to azure app service that fails npm install? 在Node中编写一个https应用并在Azure应用服务上使用 - Write an https app in Node and use it on an Azure App Service 如何在Phusion乘客的节点应用程序中使用--harmony标志? - How to use --harmony flag in my node app with phusion passenger? Azure 应用服务中的节点应用 npm install 超时,即使对于单个包,无论如何,非常不可靠 - Node app in Azure App Service npm install timeout even for single packages no matter what, extremely unreliable 在部署到azure网站时如何npm配置选项(例如--scripts-prepend-node-path)? - How to npm configuration options (such as --scripts-prepend-node-path) when deploying to azure web sites? 如何在Azure App Service上运行Node.js应用程序? - How to get Node.js app running on Azure App Service? 在Azure应用服务上安装npm软件包时出错 - Error installing npm package on Azure app service 使用 npm 在多个节点项目目录中运行脚本 - Running scripts inside multiple node project directories with npm Azure Function 节点应用程序 NPM 依赖项未解析 - Azure Function Node app NPM dependencies not resolving 我可以在Azure App Service上运行Node / ExpressJS应用程序,还是必须使用Azure Cloud Service? - Can I run a Node/ExpressJS application on Azure App Service or do I have to use Azure Cloud Service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM