-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.ts
93 lines (74 loc) · 2.55 KB
/
serverless.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import 'zone.js/dist/zone-node';
import {ngExpressEngine} from '@nguniversal/express-engine';
import * as express from 'express';
import {join} from 'path';
import {APP_BASE_HREF} from '@angular/common';
import {existsSync} from 'fs';
import {Blob} from 'blob-polyfill';
import {readFileSync} from 'fs';
import * as compression from 'compression';
import * as bodyParser from 'body-parser';
import * as cors from 'cors';
// -- solution
const template = readFileSync(join('dist', 'browser', 'index.html')).toString();
const domino = require('domino');
Object.assign(global, domino.impl);
(global as any)['KeyboardEvent'] = domino.impl.Event;
const win = domino.createWindow(template);
win.Object = Object;
win.Math = Math;
global['window'] = win;
Object.defineProperty(win.document.body.style, 'transform', {
value: () => {
return {
enumerable: true,
configurable: true
};
},
});
global['Blob'] = Blob;
global['File'] = null;
global['branch'] = null;
global['object'] = win.object;
global['MouseEvent'] = win.MouseEvent;
global['document'] = win.document;
global['HTMLElement'] = win.HTMLElement;
global['DOMTokenList'] = win.DOMTokenList;
global['getComputedStyle'] = win.getComputedStyle;
global['self'] = win;
global['CSS'] = null;
global['Prism'] = null;
global['branch'] = null;
global['object'] = win.object;
global['Node'] = win.Node;
global['Text'] = win.Text;
// const MockBrowser = require('mock-browser').mocks.MockBrowser;
// const mock = new MockBrowser();
// global['navigator'] = mock.getNavigator();
global['navigator'] = win.navigator;
// --- end solution
import {AppServerModule} from './src/main.server';
export const app = express();
app.use(compression());
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
const distFolder = join(process.cwd(), 'dist/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
app.engine('html', ngExpressEngine({
bootstrap: AppServerModule,
}));
app.set('view engine', 'html');
app.set('views', distFolder);
// Example Express Rest API endpoints
// app.get('/api/**', (req, res) => { });
// Serve static files from /browser
app.get('*.*', express.static(distFolder, {
maxAge: '1y'
}));
// All regular routes use the Universal engine
app.get('*', (req, res) => {
res.render(indexHtml, {req, providers: [{provide: APP_BASE_HREF, useValue: req.baseUrl}]});
});
export * from './src/main.server';