gpt4 book ai didi

node.js - 在Azure上部署这个nodejs应用程序有什么问题?

转载 作者:行者123 更新时间:2023-12-03 02:08:22 25 4
gpt4 key购买 nike

我已经按照本教程使用 VSCode 部署 Nodejs 应用程序(适用于 Windows):https://learn.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=windows&pivots=development-environment-vscode

不知道为什么,但它“加载”我的应用服务上的整个目录,即使使用该 SCM_DO_BUILD_DURING_DEPLOYMENT 参数:

enter image description here

这是最终的远程文件夹(另请注意 .vscode 文件夹):

enter image description here

但是,当然,它不会加载索引(基本上应该从index.js打印“欢迎”):

app.get('/', (req, res) => {
res.send('welcome!')
})

它只是说您没有查看此目录或页面的权限。

这是我的 package.json:

{
"name": "@myapp/backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "supervisor index.js",
"dev": "nodemon ./bin/www"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.2",
"cors": "^2.8.5",
"crypto": "^1.0.1",
"dotenv": "^16.0.0",
"express": "^4.17.3",
"jsonwebtoken": "^8.5.1",
"moment": "^2.29.1",
"mongoose": "^6.2.6",
"nodemailer": "^6.7.3",
"nodemailer-sendgrid-transport": "^0.2.0"
}
}

出了什么问题?

最佳答案

我遵循了所提供的相同文档,并且能够将应用程序部署到 Azure 应用服务,没有任何问题。

package.json更改 start

"scripts": {
"start": "node ./bin/www"
},

如给定文档中所述,设置 SCM_DO_BUILD_DURING_DEPLOYMENT 后命令web.config将在 Azure 应用服务中生成。但我没有看到web.config在您的文件夹结构中生成的文件。

我部署的文件夹结构 enter image description here

我自动生成的 web.config文件

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="bin/www" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^bin/www\/debug[\/]?" />
</rule>
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{PATH_INFO}"/>
</rule>

<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="bin/www"/>
</rule>
</rules>
</rewrite>

<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>

<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>

我的 package.json

{
"name": "myexpressapp",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},

"dependencies": {
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"ejs": "~2.6.1",
"express": "~4.16.1",
"http-errors": "~1.6.3",
"morgan": "~1.9.1"
}
}

我的index.js

var  express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;

确保您有SCM_DO_BUILD_DURING_DEPLOYMENT设置可在 Configuration 中使用=> Application SettingsVSCode 重新部署应用程序后.

部署的 Azure 应用程序输出 enter image description here

关于node.js - 在Azure上部署这个nodejs应用程序有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74237148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com