【发布时间】:2020-07-10 09:31:32
【问题描述】:
我有一个现有的 Node 和 Express API 应用程序,我正在尝试将其部署到 Azure WebApps。部署顺利。但是当我尝试访问 API 时,什么也没有发生。当我检查日志时,我看到以下内容:“容器 chdemoapi_0_f2df43ac 没有响应端口上的 HTTP ping:8080,站点启动失败”“容器 chdemoapi_0_4e583132 没有响应端口上的 HTTP ping:8080,站点启动失败” 这就是我的 index.js 文件的外观:
const config = require('./common/config/env.config.js');
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const AuthorizationRouter = require('./auth/routes.config');
const LeadsRouter = require('./leads/routes.config');
const DemoRouter = require('./demo/routes.config');
const MentorRouter = require('./mentors/routes.config');
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE');
res.header('Access-Control-Expose-Headers', 'Content-Length');
res.header('Access-Control-Allow-Headers', 'Accept, Authorization, Content-Type, X-Requested-With, Range, x-access-token');
if (req.method === 'OPTIONS') {
return res.send(200);
} else {
return next();
}
});
app.use(bodyParser.json());
AuthorizationRouter.routesConfig(app);
LeadsRouter.routesConfig(app);
DemoRouter.routesConfig(app);
MentorRouter.routesConfig(app);
app.listen(config.port, function () {
console.log('app listening at port %s', config.port);
});
这是我的 env.config 文件的外观:
module.exports = { "port": 3600,
//"appEndpoint": "http://localhost:3600",
//"apiEndpoint": "http://localhost:3600",
"appEndpoint": "https://chdemoapi.azurewebsites.net:3600",
"apiEndpoint": "https://chdemoapi.azurewebsites.net:3600",
"jwt_expiration_in_seconds": 36000,
"environment": "dev",
};
这就是我的 package.json 文件的外观:
{"name": "ch-demo-services",
"version": "1.0.0",
"description": "microservices for demo module",
"main": "index.js",
"start":"node index.js",
"scripts": {"test":
"echo \"Error: no test specified\" && exit 1"},
"author": "", "license": "ISC",
"dependencies": { "express": "^4.17.1", "generate-password": "^1.5.1",
"jsonwebtoken": "^8.5.1", "mailgen": "^2.0.13", "moment": "^2.27.0", "mongoose":
"^5.9.18", "nodemailer": "^6.4.10", "uuid": "^8.1.0" } }
在应用程序设置中,我还添加了 WEBSITES_PORT:3600。 在我的本地主机中,我访问的 API 如下:http://localhost:3600/listDemoSlots 部署到 Azure 后,我尝试访问它们,例如:https://chdemoapi.azurewebsites.net:3600/listDemoSlots。但是什么也没发生,我看到上面的日志。 我的设置有什么问题。
【问题讨论】:
-
您的问题解决了吗?
标签: node.js azure express azure-web-app-service