Skip to content

Commit 081f188

Browse files
committed
feat: Use prerender and dynamic render #8
1 parent 1bf6a36 commit 081f188

File tree

10 files changed

+17
-8
lines changed

10 files changed

+17
-8
lines changed

Dockerfile.ssr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ COPY . /app
44
WORKDIR /app
55
RUN npm install
66
RUN npm run build:universal
7+
RUN npm run generate:prerender
78

89
FROM node:8-alpine
910

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"ng": "ng",
77
"start": "ng serve",
8-
"ssr": "npm run build:universal && npm run server",
8+
"ssr": "npm run build:universal && npm run generate:prerender && npm run server",
99
"ssr:debug": "ng build --aot=true --output-hashing=all --named-chunks=false --build-optimizer=true && ng run universal-demo:server:dev && webpack && node server.js",
1010
"ssr:cw": "ng build --aot=true --output-hashing=all --named-chunks=false --build-optimizer=true --watch",
1111
"ssr:sw": "ng run universal-demo:server:dev --watch",

prerender.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ ROUTES.forEach(route => {
5757

5858
// Make sure the directory structure is there
5959
if (!existsSync(fullPath)) {
60-
mkdirSync(fullPath);
60+
let syncpath = BROWSER_FOLDER;
61+
route.split('/').forEach(element => {
62+
syncpath = syncpath + '/' + element;
63+
mkdirSync(syncpath);
64+
});
6165
}
6266

6367
// Writes rendered HTML to index.html, replacing the file if it already exists.

server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require(`./dist-server/mai
3535
import { ngExpressEngine } from '@nguniversal/express-engine';
3636
import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';
3737
const PORT = process.env.PORT || 4000;
38+
import { ROUTES } from './static.paths';
3839

3940
enableProdMode();
4041

@@ -88,6 +89,7 @@ app.set('view engine', 'html');
8889
app.set('views', 'src');
8990

9091
app.get('*.*', express.static(path.join(__dirname, '.', 'dist')));
92+
app.get(ROUTES, express.static(path.join(__dirname, '.', 'static')));
9193

9294
app.get('*', (req, res) => {
9395
global['navigator'] = req['headers']['user-agent'];

src/app/app.routing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const routes: Routes = [
1010
{ path: 'home', loadChildren: './home/home.module#HomeModule' },
1111
{ path: 'mock', loadChildren: './mock-server-browser/mock-server-browser.module#MockServerBrowserModule' },
1212
{ path: 'back', loadChildren: './transfer-back/transfer-back.module#TransferBackModule' },
13+
{ path: 'static/back', loadChildren: './transfer-back/transfer-back.module#TransferBackModule' },
1314
{ path: '**', loadChildren: './not-found/not-found.module#NotFoundModule' },
1415
]
1516
}

src/app/home/home.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
<h1>{{ "home.title" | translate }}</h1>
2-
<p>{{ "home.text" | translate }}</p>
3-
2+
<p>{{ "home.text" | translate }}</p>

src/app/shared/layouts/sidebar/sidebar.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const LINKS: any[] = [
44
{ link: '/home', name: 'home', icon: 'home' },
55
{ link: '/mock', name: 'mock', icon: 'info_outline' },
66
{ link: '/back', name: 'back-http', icon: 'swap_vert' },
7+
{ link: '/static/back', name: 'static-back-http', icon: 'swap_vert' },
78
];
89

910
@Component({

src/assets/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"sidebar": {
44
"home": "Home",
55
"mock": "Mock",
6-
"back-http": "Back http"
6+
"back-http": "Back http",
7+
"static-back-http": "Static `Back http`"
78
},
89
"home": {
910
"title": "Home page",

src/assets/i18n/ru.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"sidebar": {
44
"home": "Главная",
55
"mock": "Мокап",
6-
"back-http": "Http на бэк"
6+
"back-http": "Http на бэк",
7+
"static-back-http": "Статическая `Http на бэк`"
78
},
89
"home": {
910
"title": "Главная страница",

static.paths.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export const ROUTES = [
2-
'/',
3-
'/back',
2+
'/static/back',
43
];

0 commit comments

Comments
 (0)