forked from Minds/front
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-polyfills.ts
44 lines (39 loc) · 1.15 KB
/
server-polyfills.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// @ts-nocheck
import { join } from 'path';
import { readFileSync } from 'fs';
const domino = require('domino-ext');
const distFolder = join(process.cwd(), 'dist/browser/en');
const template = readFileSync(join(distFolder, 'index.html')).toString();
const win = domino.createWindow(template);
global['window'] = win;
global['Node'] = win.Node;
global['navigator'] = win.navigator;
global['screen'] = {
width: 0,
height: 0,
availHeight: 0,
availWidth: 0,
colorDepth: 0,
pixelDepth: 0,
orientation: null,
};
global['Event'] = win.Event;
global['Event']['prototype'] = win.Event.prototype;
global['KeyboardEvent'] = win.KeyboardEvent;
global['document'] = win.document;
global['window']['Promise'] = global.Promise;
global['localStorage'] = global['window']['localStorage'];
global['window']['scrollTo'] = (pos) => {};
global['fetch'] = win.fetch;
Object.defineProperty(window.document, 'cookie', {
writable: true,
value: 'myCookie=omnomnom',
});
Object.defineProperty(window.document, 'referrer', {
writable: true,
value: '',
});
Object.defineProperty(window.document, 'localStorage', {
writable: true,
value: global['window']['localStorage'],
});