import 'zone.js/dist/zone-node'; // 包括这一行
import { ngExpressEngine } from '@nguniversal/express-engine'; import { Request, Response } from 'express';
// 包括以下代码 (global as any).WebSocket = require('ws'); (global as any).XMLHttpRequest = require('xhr2');
// 这里是 express app const app = express();
app.engine('html', ngExpressEngine({ bootstrap: AppServerModuleNgFactory, }));
app.set('view engine', 'html'); app.set('views', __dirname);
// 初始化 keycloak-angular 插件 app.use(keycloak.middleware({ ... // 配置对应的url // 例如:url: 'http://localhost/auth', ... }));
app.use(express.static(${__dirname}/static
, { index: false }));
app.get('.', express.static(${__dirname}/static
, {
maxAge: '1y'
}));
// 渲染页面及传递 keycloak 的信息 app.get('*', (req: Request, res: Response) => { res.render('index', { req, res, providers: [ // 同上,也应该配置 keycloak ... ] }); });
// 监听本地端口,默认为 4000 app.listen(process.env.PORT || 4000, () => { console.log('Server listening'); });
上一篇:AngularSSR中的ERR_TOO_MANY_REDIRECTS问题
下一篇:AngularStackblitz错误:Uncaught(在Promise中):错误:已经加载了“BrowserModule”的提供程序。