0

I'm trying to host a node app on www.domain.com/nodeapp. I've already got www.domain.com website hosted on apache server. I've created a reverse proxy in apache configuration.

ProxyPass /nodeapp http://localhost:3100/nodeapp
ProxyPassReverse /nodeapp http://localhost:3100/nodeapp

This is MEAN app's folder structure And below is my node app.js file where I'm linking my angular app in dist folder (which I built using ng build --prod)

app.use("/api/posts", postsRoutes);
app.use("/api/user", userRoutes);
app.use("/api/client", clientRoutes);

app.use("/", express.static(path.join(__dirname, "angular")));

app.use((req, res, next) => {
    res.sendFile(path.join(__dirname, "angular", "index.html"));
});

module.exports = app;

When I run the node server.js file on port 3000. Only the index.html loads and other static files throws an 404.

I tired then adding an empty base-href ng build --prod --base href while building the angular app which loaded the app with static resources properly but when I navigate in angular app like www.domain.com/nodeapp/auth/login directly in the URL the path of the static file shows www.domain.com/nodeapp/auth/login/style.css which is obviously incorrect. The API links for e.g. (http://localhost:3100/api/posts) doesn't work when accessed using Reverse proxy.

What am I doing wrong here? Is there any working guide where a MEAN app is hosted along side an apache server?

0 Answers0