Revision 57444
Added by Konstantinos Triantafyllou over 4 years ago
modules/uoa-connect-portal/trunk/server.ts | ||
---|---|---|
26 | 26 |
import {ngExpressEngine, RenderOptions} from '@nguniversal/express-engine'; |
27 | 27 |
// Import module map for lazy loading |
28 | 28 |
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader'; |
29 |
import {REQUEST, RESPONSE} from "@nguniversal/express-engine/tokens"; |
|
29 | 30 |
|
30 | 31 |
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine) |
31 | 32 |
// app.engine('html', ngExpressEngine({ |
... | ... | |
37 | 38 |
// })); |
38 | 39 |
|
39 | 40 |
// be able to get request and get domain from there |
40 |
app.engine('html', (_, options: RenderOptions, callback) => { |
|
41 |
let engine = ngExpressEngine({ |
|
42 |
bootstrap: AppServerModuleNgFactory, |
|
43 |
providers: [ |
|
44 |
{ provide: 'request', useFactory: () => options.req, deps: [] }, |
|
45 |
provideModuleMap(LAZY_MODULE_MAP) |
|
46 |
] |
|
47 |
}); |
|
48 |
engine(_, options, callback); |
|
41 |
|
|
42 |
app.engine('html', (_, options: any, callback) => { |
|
43 |
const opts = { |
|
44 |
document: template, |
|
45 |
url: options.req.url, |
|
46 |
extraProviders: [ |
|
47 |
provideModuleMap(LAZY_MODULE_MAP), |
|
48 |
{ |
|
49 |
provide: REQUEST, |
|
50 |
useValue: options.req |
|
51 |
}, |
|
52 |
{ |
|
53 |
provide: RESPONSE, |
|
54 |
useValue: options.req.res, |
|
55 |
}, |
|
56 |
] |
|
57 |
}; |
|
58 |
|
|
59 |
renderModuleFactory(AppServerModuleNgFactory, opts) |
|
60 |
.then(html => callback(null, html) |
|
61 |
); |
|
49 | 62 |
}); |
50 | 63 |
|
51 | 64 |
app.set('view engine', 'html'); |
Also available in: Unified diff
[Connect]: Add on server REQUEST and RESPONSE providers