Skip to content

Commit 07f7f38

Browse files
committed
most important hack global variables
1 parent 985a501 commit 07f7f38

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

server.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
const domino = require('domino');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const template = fs.readFileSync(path.join(__dirname, '.', 'dist', 'index.html')).toString();
5+
const win = domino.createWindow(template);
6+
global['window'] = win;
7+
global['document'] = win.document;
8+
// global['XMLHttpRequest'] = require('xmlhttprequest').XMLHttpRequest;
9+
global['Prism'] = null;
10+
111
import { HttpClient } from '@angular/common/http';
212
import 'reflect-metadata';
313
import 'zone.js/dist/zone-node';
@@ -7,9 +17,6 @@ import * as compression from 'compression';
717
import * as cookieparser from 'cookie-parser';
818
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');
919

10-
const fs = require('fs');
11-
const path = require('path');
12-
1320
const files = fs.readdirSync(`${process.cwd()}/dist-server`);
1421
const mainFiles = files.filter(file => file.startsWith('main'));
1522
const hash = mainFiles[0].split('.')[1];
@@ -24,7 +31,6 @@ const app = express();
2431
app.use(compression());
2532
app.use(cookieparser());
2633

27-
const template = fs.readFileSync(path.join(__dirname, '.', 'dist', 'index.html')).toString();
2834

2935
app.engine('html', ngExpressEngine({
3036
bootstrap: AppServerModuleNgFactory,
@@ -39,12 +45,7 @@ app.set('views', 'src');
3945
app.get('*.*', express.static(path.join(__dirname, '.', 'dist')));
4046

4147
app.get('*', (req, res) => {
42-
global['window'] = global;
43-
global['document'] = template;
4448
global['navigator'] = req['headers']['user-agent'];
45-
global['CSS'] = null;
46-
// global['XMLHttpRequest'] = require('xmlhttprequest').XMLHttpRequest;
47-
global['Prism'] = null;
4849

4950
res.render('../dist/index', {
5051
req: req,

0 commit comments

Comments
 (0)