|
1 | 1 | import 'zone.js/dist/zone-node';
|
2 | 2 | import 'reflect-metadata';
|
3 |
| -import {enableProdMode} from '@angular/core'; |
| 3 | +import { enableProdMode } from '@angular/core'; |
| 4 | + |
4 | 5 | // Express Engine
|
5 |
| -import {ngExpressEngine} from '@nguniversal/express-engine'; |
| 6 | +import { ngExpressEngine } from '@nguniversal/express-engine'; |
6 | 7 | // Import module map for lazy loading
|
7 |
| -import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader'; |
| 8 | +import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader'; |
8 | 9 |
|
9 | 10 | import * as express from 'express';
|
10 |
| -import {join} from 'path'; |
| 11 | +import { join } from 'path'; |
11 | 12 |
|
12 | 13 | // Faster server renders w/ Prod mode (dev mode never needed)
|
13 | 14 | enableProdMode();
|
14 | 15 |
|
15 | 16 | // Express server
|
16 | 17 | const app = express();
|
17 | 18 |
|
18 |
| -const PORT = process.env.PORT || 8000; |
| 19 | +const PORT = process.env.PORT || 4000; |
19 | 20 | const DIST_FOLDER = join(process.cwd(), 'dist');
|
20 | 21 |
|
21 | 22 | // * NOTE :: leave this as require() since this file is built Dynamically from webpack
|
22 |
| -const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./server/main'); |
| 23 | +const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./server/main'); |
23 | 24 |
|
24 | 25 | // Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
|
25 | 26 | app.engine('html', ngExpressEngine({
|
26 | 27 | bootstrap: AppServerModuleNgFactory,
|
27 | 28 | providers: [
|
28 |
| - provideModuleMap(LAZY_MODULE_MAP) |
| 29 | + provideModuleMap(LAZY_MODULE_MAP), |
| 30 | + // In case you want to use an AppShell with SSR and Lazy loading |
| 31 | + // you'd need to uncomment the below. (see: https://github.com/angular/angular-cli/issues/9202) |
| 32 | + // { |
| 33 | + // provide: NgModuleFactoryLoader, |
| 34 | + // useClass: ModuleMapNgFactoryLoader, |
| 35 | + // deps: [ |
| 36 | + // Compiler, |
| 37 | + // MODULE_MAP |
| 38 | + // ], |
| 39 | + // }, |
29 | 40 | ]
|
30 | 41 | }));
|
31 | 42 |
|
32 | 43 | app.set('view engine', 'html');
|
33 | 44 | app.set('views', join(DIST_FOLDER, 'browser'));
|
34 | 45 |
|
35 |
| -/* - Example Express Rest API endpoints - |
36 |
| - app.get('/api/**', (req, res) => { }); |
37 |
| -*/ |
| 46 | +// Example Express Rest API endpoints |
| 47 | +// app.get('/api/**', (req, res) => { }); |
38 | 48 |
|
39 | 49 | // Server static files from /browser
|
40 | 50 | app.get('*.*', express.static(join(DIST_FOLDER, 'browser'), {
|
41 | 51 | maxAge: '1y'
|
42 | 52 | }));
|
43 | 53 |
|
44 |
| -// ALl regular routes use the Universal engine |
| 54 | +// All regular routes use the Universal engine |
45 | 55 | app.get('*', (req, res) => {
|
46 | 56 | res.render('index', { req });
|
47 | 57 | });
|
|
0 commit comments