简体   繁体   中英

Node, Express API App on Azure giving Container Start Failure error

I have an existing Node and Express API application which I am trying to deploy to Azure WebApps. Deployment goes fine. But when I try to access the APIs, nothing happens. When I check log, I see following: "Container chdemoapi_0_f2df43ac didn't respond to HTTP pings on port: 8080, failing site start""Container chdemoapi_0_4e583132 didn't respond to HTTP pings on port: 8080, failing site start" This is how my index.js file looks:

    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);
});

This is how my env.config file looks:

 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",    
};

This is how my package.json file looks:

{"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"      }    }    

In Application settings, I have also added WEBSITES_PORT:3600. In my localhost, I was accessing API like: http://localhost:3600/listDemoSlotsAfter deploying to Azure, I am trying to access them like: https://chdemoapi.azurewebsites.net:3600/listDemoSlots . But nothing happens and I see above logs. What's wrong with my settings.

From the point of view of your error message, it is the port problem.

Azure Web App service only supports http port 80 and https port 443 . It is recommended to replace https://chdemoapi.azurewebsites.net:3600 with https://chdemoapi.azurewebsites.net:443 . Then restart the application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM