Я следовал этому руководству по развертыванию приложения nodejs с помощью VSCode для Windows: https://learn.microsoft.com/en-us/azure/app-service/quickstart-nodejs?tabs=windows&pivots=development-environment- код
не знаю почему, но он «загружает» весь каталог в мою службу приложений, даже если используется этот параметр SCM_DO_BUILD_DURING_DEPLOYMENT:
Вот последняя удаленная папка (обратите внимание на папку .vscode):
Но, конечно, он ничего не загружает в индекс (который должен в основном печатать «приветствие» из 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
файла, сгенерированного в вашей структуре папок.
Моя развернутая структура папок
Мой автоматически сгенерированный файл 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 Settings
после повторного развертывания приложения из VSCode
.
Выходные данные развернутого приложения Azure