Skip to content

Commit 55fc1e4

Browse files
committed
Using domino for Angular server side rendering #13
1 parent df58bb5 commit 55fc1e4

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

project/application/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

project/application/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@nguniversal/module-map-ngfactory-loader": "6.0.0",
3131
"classlist.js": "^1.1.20150312",
3232
"core-js": "^2.5.4",
33+
"domino": "^2.1.0",
3334
"es5-shim": "^4.5.10",
3435
"es6-shim": "^0.35.3",
3536
"rxjs": "^6.0.0",

project/application/server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';
2727

2828
// Our index.html we'll use as our template
2929
const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString();
30+
const domino = require('domino');
31+
const win = domino.createWindow(template);
32+
33+
global['window'] = win;
34+
global['document'] = win.document;
3035

3136
app.engine('html', (_, options, callback) => {
3237
renderModuleFactory(AppServerModuleNgFactory, {
@@ -58,6 +63,7 @@ app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));
5863

5964
// All regular routes use the Universal engine
6065
app.get('*', (req, res) => {
66+
global['navigator'] = req['headers']['user-agent'];
6167
res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req });
6268
});
6369

0 commit comments

Comments
 (0)