angular - 在一个 Express 应用程序中提供多个 Angular Universal 应用程序

标签 angular express angular-universal

我有两个使用 angular-cli 制作的不同 Angular 应用程序,它们都已修改为通过 Angular Universal 在 Node.js 服务器上运行,如下 Angular's tutorial ,但该示例只能服务于一个应用程序。

该示例创建一个 View 引擎:

app.engine('html', (_, options, callback) => {
  renderModuleFactory(AppServerModuleNgFactory, {
    // Our index.html
    document: template,
    url: options.req.url,
    // DI so that we can get lazy-loading to work differently (since we need it to just instantly render it)
    extraProviders: [
      provideModuleMap(LAZY_MODULE_MAP)
    ]
  }).then(html => {
    callback(null, html);
  });
});

app.set('view engine', 'html');

由于每个应用程序都有不同的 index.html 文件,因此我需要创建两个 View 引擎,但如何告诉 Express 在一条 route 使用一个引擎,在另一条 route 使用另一个引擎? 换句话说,如何将 app1 映射到 /app1 并将 app2 映射到 /app2

最佳答案

Express应用程序可以挂载多个sub-applications到不同的端点:

const app1 = express();
const app2 = express();
...
app.use('/app1', app1);
app.use('/app2', app2);
app.listen(3000);

子应用程序可以有自己的设置,不应监听

关于angular - 在一个 Express 应用程序中提供多个 Angular Universal 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47213012/

相关文章:

Firebase HTTP 到 HTTPS NGINX 重定向自定义域,删除 GET 的 POST 方法

angular - 是否可以使用 Angular 拦截器拦截像 .html 这样的静态文件?我想改变 lang 属性

javascript - Angular 2 : Toggle buttons are not working as expected

angular - 如何从垫表 Material 设计中删除垫行

node.js - 使用 $in 和 $elemMatch 匹配两个字段之一

node.js - 使用 Zombie 测试 Node.js 应用程序

angular - 当我刷新我的网站时,我只在 IE11 和 Edge、Angular 5、Tomcat 的控制台中得到 404

angular - 必须有要重构的源文件中的错误

angular - 您如何在服务器端使用 angular universal 渲染 angular 应用程序并使用 ssl 证书?

Angular 通用 : Adding a service worker doesn't allow specific titles for pages