【问题标题】:Node.js serve two AngularJS projects in a single solutionNode.js 在一个解决方案中为两个 AngularJS 项目提供服务
【发布时间】:2018-02-24 04:09:56
【问题描述】:

我正在做一个包含两个模块的 MEAN 应用程序。

  1. 访客
  2. 管理区

我想在两个单独的 AngularJS 项目中完成上述两个领域,因为它们在功能和设计上都有很大不同。这是我的目录结构。

但问题是当我在下面使用两行代码时

app.use(express.static(path.join(__dirname, 'client/frontend/app')));
app.use(express.static(path.join(__dirname, 'client/admin/app')));

它不会起作用。

这是我的路线

app.get('/admin/*', function(req, res) {
  res.sendfile('./client/admin/app/index.html'); 
});
app.get('*', function(req, res) {
  res.sendfile('./client/frontend/app/index.html'); 
});

我该怎么做?

我的最后一个选择是将两个索引文件放在同一个目录中,但名称不同。除此之外还有其他选择吗?

【问题讨论】:

  • 使用res.sendFile(__dirname+'/client/admin/app/index.html');
  • @mukesh 会尽快更新您的信息
  • @mukesh 我试过了。它不工作
  • 您的应用运行良好吗?如何?
  • 是的,我在更多项目中实现了相同

标签: angularjs node.js mean-stack


【解决方案1】:

如果你想拥有例如/ 中的普通应用程序和/admin 中的管理应用程序:

app.use('/', express.static(path.join(__dirname, 'client/frontend/app')));
app.use('/admin', express.static(path.join(__dirname, 'client/admin/app')));

这就是你要找的吗?

【讨论】:

  • 只有第一个路由工作。第二个路由索引文件被渲染,但其他文件没有交付。
  • 这是因为我忘记在管理选项卡中设置基本 href
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-04
  • 2020-05-08
相关资源
最近更新 更多