I am deploying a web application that uses NodeJS, Express and React on Azure App Service (plugged to my BitBucket repo), and I'm not finding success. Either the deployment fails, or it claims it is successful, but the site is unaccessible and keeps timing out. When I check the Docker logs in my Azure diagnosis, I notice the following:
2021-02-14T13:41:53.578Z INFO - Initiating warmup request to container mcm-app_0_543ad0c3 for site mcm-app
And after several logs that read Waiting for response to warmup request for container mcm-app_0_543ad0c3
, I get the following:
2021-02-14T13:45:44.205Z ERROR - Container mcm-app_0_543ad0c3 for site mcm-app did not start within expected time limit. Elapsed time = 230.6269687 sec
2021-02-14T13:45:44.236Z ERROR - Container mcm-app_0_543ad0c3 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2021-02-14T13:45:44.299Z INFO - Stopping site mcm-app because it failed during startup.
This is what my server.js
file for the Express backend looks like:
var express = require("express");
var cors = require("cors");
var app = express();
var path = require("path");
const port = process.env.PORT || 8080;
// Enable CORS and handle JSON requests
app.use(cors());
app.use(express.json());
app.post("/", function (req, res, next) {
// console.log(req.body);
res.json({ msg: "This is CORS-enabled for all origins!" });
});
// Set router for email notifications
const mailRouter = require("./routers/mail");
const readerRouter = require("./routers/reader");
const notificationsRouter = require("./routers/booking-notifications");
app.use("/email", mailRouter);
app.use("/reader", readerRouter);
app.use("/notifications", notificationsRouter);
app.use(express.static("./mcm-app/build"));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "mcm-app", "build", "index.html"));
});
app.listen(port, () => {
// console.log(`Server is running on port: ${port}`);
});
My client's package.json
does not contain any proxy
command, by the way. I removed it. The error appears with/without it anyway.
Also, per some recommendations, I've tried setting WEBSITES_PORT
to 8080 in my Azure configurations. But nothing works so far.
I'd appreciate it if I could get some detailed guidance to resolve this. I'm not using a .yml file, in case that helps.
process.env.PORT
in your code, so your webapp application actually uses port80 or 443
, and yourWEBSITES_PORT
is invalid. Because only one port can be exposed in the container, I think8080
is invalid. – Jason Panconst port = process.env.PORT || 8080;
toconst port = 8080;
, and then follow the cli command in the screenshot to set it. – Jason Pan