Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Angular-Universal-Demo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bui Thanh Tung
Angular-Universal-Demo
Commits
6c8b2383
Commit
6c8b2383
authored
Feb 03, 2020
by
Bui Thanh Tung
👁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.md
parent
6a337d14
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
README.md
README.md
+11
-11
No files found.
README.md
View file @
6c8b2383
...
...
@@ -3,27 +3,27 @@
## Cấu trúc 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
B1: Clone từ Git
B2: Download thư viện
-
Run '
npm install
'
-
Run '
***npm install**
*
'
B3: Chạy project Angular (Terminal 1)
-
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
+
npm run build:ssr
:
-
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
+
***npm run build:ssr**
*
:
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
+
npm run serve:ssr
+
***npm run serve:ssr**
*
:
Run Node Express server ./dist/server.js đã được build ở trên
B4: Chạy API để test (Terminal 2)
-
Mở 1 Terminal khác để chạy server API
-
Run '
node API_DEMO.js
'
-
Run '
***node API_DEMO.js**
*
'
-
B5: http://localhost:4000/
...
...
@@ -35,12 +35,12 @@ B5: http://localhost:4000/
console.log('Browser Request Node Server to render WebApp');
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 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/
// 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
*
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.
...
...
@@ -63,7 +63,7 @@ B5: http://localhost:4000/
document.
location.
localstorage.
o
...........
}
.....loading 🙃🙃🙃🙃🙃🙃🙃
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment