将Angular项目移至Express应用的子目录

时间:2018-09-28 15:45:43

标签: angular express

我想将我的静态页面与我的角度应用程序分开提供-基本上,我有一个成员区域,即我的角度应用程序...以及大量的静态html ...

所以我有这样的明确路线

app.use(express.static(path.join(__dirname,'public')));
app.use(express.static(path.join(__dirname,'members')));

app.get('/', (req,res) => {
    res.sendFile(path.join(__dirname,'public/index.html'));
})
app.get('/members/', (req,res) => {
    res.sendFile(path.join(__dirname,'members/index.html'));
})

app.listen(port, ()=>{
    console.log('Started on port ' + port);
})

我跑步     ng build --prod --aot --base-href / members /

我将dist文件夹重命名为“成员”

现在我得到了所有捆绑软件文件的404,例如

GET http://localhost:3002/members/inline.318b50c57b4eba3d437b.bundle.js net::ERR_ABORTED 404 (Not Found)

我在做什么错?该文件位于该路径中。...

dir结构看起来像这样

app.js 
  /public
     |-- index.html
  /members
     |-- index.html
     |-- inline...bundle.js
     |-- main...bundle.js
     |-- polyfills...bundle.js
     |-- styles...bundle.css

1 个答案:

答案 0 :(得分:1)

您需要将其更改为ng build -prod --base-href /members

由于某些原因,我们还不知道,最后的/表示放置项目整个路径的角度。