
我正在嘗試在 www.domain.com/nodeapp 上託管一個節點應用程式。我已經在 apache 伺服器上託管了 www.domain.com 網站。我在 apache 配置中建立了一個反向代理。
ProxyPass /nodeapp http://localhost:3100/nodeapp
ProxyPassReverse /nodeapp http://localhost:3100/nodeapp
這是 MEAN 應用程式的
資料夾結構
下面是我的節點 app.js 文件,我在其中連結 dist 資料夾中的角度應用程式(我使用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;
當我在連接埠 3000 上運行節點 server.js 檔案時。
ng build --prod --base href
我厭倦了在構建角度應用程式時添加一個空的base-href ,該應用程式正確地加載了帶有靜態資源的應用程序,但是當我在角度應用程式中導航時,就像www.domain.com/nodeapp/auth/login
直接在URL中一樣,靜態文件的路徑顯示www.domain.com/nodeapp/auth/login/style.css
這顯然是不正確的。使用反向代理存取時,例如 ( ) 的 API 連結http://localhost:3100/api/posts
不起作用。
我在這裡做錯了什麼?是否有任何工作指南可以將 MEAN 應用程式與 apache 伺服器一起託管?