-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add support for server side rendering with universal
- Loading branch information
Showing
9 changed files
with
154 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {ServerModule} from '@angular/platform-server'; | ||
|
||
import {AppModule} from './app.module'; | ||
import {AppComponent} from './app.component'; | ||
|
||
@NgModule({ | ||
imports: [AppModule, ServerModule], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppServerModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
///<reference types="node"/> | ||
import "zone.js/dist/zone-node"; | ||
|
||
import { ngExpressEngine } from "@nguniversal/express-engine"; | ||
import * as express from "express"; | ||
import { join } from "path"; | ||
|
||
const app = express(); | ||
|
||
const PORT = process.env.PORT || 4000; | ||
const DIST_FOLDER = join(process.cwd(), "src/prodapp"); | ||
|
||
import { AppServerModule } from "./app/app.server.module"; | ||
|
||
app.engine( | ||
"html", | ||
ngExpressEngine({ | ||
bootstrap: AppServerModule, | ||
providers: [ | ||
// TODO add support for lazy loading with server side rendering | ||
// provideModuleMap(LAZY_MODULE_MAP) | ||
] | ||
}) as any | ||
); | ||
|
||
app.set("view engine", "html"); | ||
app.set("views", DIST_FOLDER); | ||
|
||
app.get("*.*", express.static(DIST_FOLDER, { maxAge: "1y" })); | ||
|
||
// catch /favicon.ico route to prevent the following server error: | ||
// Error: Cannot match any routes. URL Segment: 'favicon.ico' | ||
app.get("/favicon.ico", (req, res) => res.send("")); | ||
|
||
app.get("*", (req, res) => { | ||
res.render("example/index", { req }); | ||
}); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Node Express server listening on http://localhost:${PORT}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./out-tsc/app-server", | ||
"module": "commonjs", | ||
"types": ["node"] | ||
}, | ||
"files": ["src/main.server.ts", "server.ts"], | ||
"angularCompilerOptions": { | ||
"entryModule": "./src/app/app.server.module#AppServerModule" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,14 @@ | |
resolved "https://registry.yarnpkg.com/@angular/platform-browser/-/platform-browser-9.0.0.tgz#b9454f29d8edaf024668baa9e07083eef73deac2" | ||
integrity sha512-2PR/o57HjZvKEnAF8ODeqxmeC90oth9dLTMrJNoI5MET0IeErKeI/9Sl5cLQuXC+lSVN5rOMCvDb74VWSno5yw== | ||
|
||
"@angular/platform-server@^9.0.0": | ||
version "9.1.0" | ||
resolved "https://registry.yarnpkg.com/@angular/platform-server/-/platform-server-9.1.0.tgz#a4d5b20724acd54219603e32cee88b0b58ee6617" | ||
integrity sha512-JboTIUBgf9yHRjF93q8NJQoeIp5Zp4kg8Nmw1QLWO6SV+OpiOpKSrlScMVncCh0KiU6SIOmiuHJwBhLm78fi+Q== | ||
dependencies: | ||
domino "^2.1.2" | ||
xhr2 "^0.1.4" | ||
|
||
"@angular/[email protected]": | ||
version "9.0.0" | ||
resolved "https://registry.yarnpkg.com/@angular/router/-/router-9.0.0.tgz#11784fc8ce9cb3314c7ec1083ff9be7c611181c2" | ||
|
@@ -901,6 +909,18 @@ | |
resolved "https://registry.yarnpkg.com/@ngrx/store/-/store-9.0.0-beta.0.tgz#b352f0394b1b652ee2ae2039ba1757a704290846" | ||
integrity sha512-yfw+Qwiu3fNjjRD1B2ZSGpjd3a70fLjFfqhu2H636giia5cTnqbzIqOH3EnZzapADzwL6M7yy7tixWpJ24lbpQ== | ||
|
||
"@nguniversal/[email protected]": | ||
version "9.1.0" | ||
resolved "https://registry.yarnpkg.com/@nguniversal/common/-/common-9.1.0.tgz#01ac2d2c47c6d04f955f1713697377afcaa1ad91" | ||
integrity sha512-Pvb3KhuV44PxLmVOf1dqnuckdaNdfT5tbiUu2/vVbdtyFdQpF40D1Zx4RumRymK0ZzTJGQsJtJSi2DJvvGgwMg== | ||
|
||
"@nguniversal/express-engine@^9.0.0": | ||
version "9.1.0" | ||
resolved "https://registry.yarnpkg.com/@nguniversal/express-engine/-/express-engine-9.1.0.tgz#ddc1cecb4134a365142a9ba6ebb6ae8f99cb2ad1" | ||
integrity sha512-uRb8dJD3huk42eY1iOpmr8yfq/LTSOoUfKY4eVREE7nMePyZNSRQHNCEybHDTNh43FvTN38u+cA4dTlmMFD5GQ== | ||
dependencies: | ||
"@nguniversal/common" "9.1.0" | ||
|
||
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf" | ||
|
@@ -2407,6 +2427,11 @@ dom-serialize@^2.2.0: | |
extend "^3.0.0" | ||
void-elements "^2.0.0" | ||
|
||
domino@^2.1.2: | ||
version "2.1.4" | ||
resolved "https://registry.yarnpkg.com/domino/-/domino-2.1.4.tgz#78922e7fab7c610f35792b6c745b7962d342e9c4" | ||
integrity sha512-l70mlQ7IjPKC8kT7GljQXJZmt5OqFL+RE91ik5y5WWQtsd9wP8R7gpFnNu96fK5MqAAZRXfLLsnzKtkty5fWGQ== | ||
|
||
dot-prop@^4.1.0: | ||
version "4.2.0" | ||
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57" | ||
|
@@ -7280,6 +7305,11 @@ xdg-basedir@^3.0.0: | |
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4" | ||
integrity sha1-SWsswQnsqNus/i3HK2A8F8WHCtQ= | ||
|
||
xhr2@^0.1.4: | ||
version "0.1.4" | ||
resolved "https://registry.yarnpkg.com/xhr2/-/xhr2-0.1.4.tgz#7f87658847716db5026323812f818cadab387a5f" | ||
integrity sha1-f4dliEdxbbUCYyOBL4GMras4el8= | ||
|
||
xml2js@^0.4.17: | ||
version "0.4.22" | ||
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.22.tgz#4fa2d846ec803237de86f30aa9b5f70b6600de02" | ||
|