Question
Unable to connect to the node app
Hi guys, I’m kinda new to all the stuff related to deployment, servers, etc.
I followed tutorials explaining how to setup a Linux 18 server with nginx, and the example worked properly.
However, when I redirect the proxy to my application and then try to access it via a browser, I have a 502 error.
Here’s the code of my node app :
const https = require("https");
const express = require("express");
const app = express();
const dotenv = require("dotenv");
const mongoose = require("mongoose");
const cors = require("cors");
const mustacheExpress = require("mustache-express");
dotenv.config();
// Connect to DB
mongoose.connect(process.env.DB_CONNECT, { useNewUrlParser: true }, () => {
console.log("connected to DB !");
});
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
// Middleware
app.use(express.json());
// Templating
app.engine("html", mustacheExpress());
//import routes
const authRoute = require("./routes/auth");
const devisRoute = require("./routes/devis");
const messageRoute = require("./routes/message");
const actuRoute = require("./routes/actu");
//Routes middlewares
app.use("/api/user", authRoute);
app.use("/api/sendDevis", devisRoute);
app.use("/api/message", messageRoute);
app.use("/api/actu", actuRoute);
// app.get("/", (req, res) => {
// return res.status(200).json({ status: "OK" });
// });
app.use(express.static("../front-end/dist/natan-website"));
app.get("/", function (req, res, next) {
res.redirect("/");
});
app.listen(3000, () => console.log("Server is running !"));
Does anyone have an idea of the mistake I’ve made ?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×