Commit 6a337d14 authored by Bui Thanh Tung's avatar Bui Thanh Tung 👁

Update README.md

parent 4886eac4
Pipeline #920 failed with stages
...@@ -7,23 +7,27 @@ ...@@ -7,23 +7,27 @@
## Setup project ## Setup project
B1: Clone từ Git B1: Clone từ Git
B2: Download thư viện B2: Download thư viện
- Run 'npm install' - Run 'npm install'
B3: Chạy project Angular (Terminal 1) B3: Chạy project Angular (Terminal 1)
- Client-Side-Rendering: Run 'npm start' bình thường: Dùng khi coding - Client-Side-Rendering: Run 'npm start' bình thường: Dùng khi coding
- Server-Side-Rendering: Run 'npm run build:ssr && npm run serve:ssr' : Dùng khi build prod - Server-Side-Rendering: Run 'npm run build:ssr && npm run serve:ssr' : Dùng khi build prod
+ npm run build:ssr: + npm run build:ssr:
Build project prod và dùng các file cấu hình có tên '*.server.*' Build project prod và dùng các file cấu hình có tên '*.server.*'
Sau khi build sẽ sinh ra 1 Node Express server trong thư mục ./dist/ (./dist/server.js) Sau khi build sẽ sinh ra 1 Node Express server trong thư mục ./dist/ (./dist/server.js)
Thư mục ./browser/ là phần code Angular được đóng gói Thư mục ./browser/ là phần code Angular được đóng gói
+ npm run serve:ssr + npm run serve:ssr
Run Node Express server ./dist/server.js đã được build ở trên Run Node Express server ./dist/server.js đã được build ở trên
B4: Chạy API để test (Terminal 2) B4: Chạy API để test (Terminal 2)
- Mở 1 Terminal khác để chạy server API - Mở 1 Terminal khác để chạy server API
- Run 'node API_DEMO.js' - Run 'node API_DEMO.js'
-
B5: http://localhost:4000/ B5: http://localhost:4000/
## ----------- Ghi chú --------------- ## ----------- Dev ---------------
* Cấu hình Filter Request của node server * Cấu hình Filter Request của node server
- Với các API để gọi để render WebApp - Với các API để gọi để render WebApp
// All regular routes use the Universal engine // All regular routes use the Universal engine
...@@ -39,5 +43,30 @@ B5: http://localhost:4000/ ...@@ -39,5 +43,30 @@ B5: http://localhost:4000/
app.get('*.*', express.static(join(DIST_FOLDER, 'browser'))); app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));
- Tài liệu: https://angular.io/guide/universal#filtering-request-urls - Tài liệu: https://angular.io/guide/universal#filtering-request-urls
* Lưu ý khi coding * Lưu ý khi coding
- Do việc khi Render trên server của Node ................................... - Do khi dùng SSR phải render trên server node và do trên server không thể truy cập được một số tài nguyên của trình duyệt như 'document', 'window', 'location',... nên khi coding phải lưu ý khi dùng những thứ trên phải check platform là browswer.
- Tài liệu: https://angular.io/guide/universal#working-around-the-browser-apis
// import thư viện common
import { isPlatformServer } from '@angular/common';
// inject token flatformid trong contructor
constructor(@Inject(PLATFORM_ID) private platformId: any) {}
// khi dùng tài nguyên browser
if (isPlatformBrowser(this.platformId)) {
document.
location.
localstorage.
o
}
.....loading 🙃🙃🙃🙃🙃🙃🙃
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment