1
votes

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.

1
In your code, I saw process.env.PORT in your code, so your webapp application actually uses port 80 or 443, and your WEBSITES_PORT is invalid. Because only one port can be exposed in the container, I think 8080 is invalid.Jason Pan
You try to modify const port = process.env.PORT || 8080; to const port = 8080;, and then follow the cli command in the screenshot to set it.Jason Pan
In azure web app, it only support 80/443 port. But you can set it like pic ,when you delpoy your webapp, it will always route to 8080 port. If my comment useful to you, pls let me know.Jason Pan
@JasonPan Thanks for the suggestions. Before you posted your answers, I actually proceeded to use Docker Compose to deploy my test application instead. So it's all good now: stackoverflow.com/a/66213919/1536240Isaac Asante
You can post your answer below and share your solution with everyone, which will help many people. I have seen many similar posts before. ^-^Jason Pan

1 Answers

1
votes

I found Isaac has managed to resolve this issue with below solution.

Adding tty: true for it in docker-compose.yml file. Also, to make the frontend-backend interaction work as expected in the app, changing proxy command in client's package.json to the following:

"proxy": "http://backend:5000"

And changing links command in docker-compose.yml to this:

  - "backend:be"

Sharing the answer here to help others who may encounter the same issue in the future.