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

Update README.md

parent 6a337d14
...@@ -3,27 +3,27 @@ ...@@ -3,27 +3,27 @@
## Cấu trúc Project ## Cấu trúc Project
- Angular Project - Angular Project
- Restful API Demo chạy với Node Express server (./API_DEMO.js) - Restful API Demo chạy với Node Express server (*./API_DEMO.js*)
## 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/
...@@ -35,12 +35,12 @@ B5: http://localhost:4000/ ...@@ -35,12 +35,12 @@ B5: http://localhost:4000/
console.log('Browser Request Node Server to render WebApp'); console.log('Browser Request Node Server to render WebApp');
res.render('index', { req }); res.render('index', { req });
}); });
+ Khi các Request vào trường hợp này thì Express server sẽ chạy (res.render('index', { req })) WebApp lần 1(Kể cả việc gọi API để lấy data), + Khi các Request vào trường hợp này thì Express server sẽ chạy (*res.render('index', { req })*) WebApp lần 1(Kể cả việc gọi API để lấy data),
sau khi chạy xong sẽ render ra HTML gán vào Response trả về của Request vừa được gọi rồi trả ra ra trình duyệt sau khi chạy xong sẽ render ra HTML gán vào Response trả về của Request vừa được gọi rồi trả ra ra trình duyệt
+ Sau Trình duyệt được trả ra thì WebApp lại chạy lần 2 (Hiện tại đang thấy gọi API lần 2) để update vào view + Sau Trình duyệt được trả ra thì WebApp lại chạy lần 2 (Hiện tại đang thấy gọi API lần 2) để update vào view
- Với các kiểu API truy cập tài nguyên của server thì đang chỉ cho truy cập vào thư mục ./dist/browser/ - Với các kiểu API truy cập tài nguyên của server thì đang chỉ cho truy cập vào thư mục ./dist/browser/
// Server static files from /browser // Server static files from /browser
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 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. - 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.
...@@ -63,7 +63,7 @@ B5: http://localhost:4000/ ...@@ -63,7 +63,7 @@ B5: http://localhost:4000/
document. document.
location. location.
localstorage. localstorage.
o ...........
} }
.....loading 🙃🙃🙃🙃🙃🙃🙃 .....loading 🙃🙃🙃🙃🙃🙃🙃
......
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