-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add ssr to the app #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Caution Review failedThe pull request is closed. """ WalkthroughThe changes introduce server-side rendering (SSR) and prerendering capabilities to the Angular frontend application. This includes new build, serve, and prerender targets, server-specific configuration and entry files, an Express-based SSR server, updated TypeScript and Nx configurations, and added dependencies for Angular Universal and Express. Changes
Sequence Diagram(s)sequenceDiagram
participant Browser
participant ExpressServer
participant AngularEngine
Browser->>ExpressServer: HTTP Request (e.g., /)
ExpressServer->>AngularEngine: Render page (with route info)
AngularEngine-->>ExpressServer: HTML Response
ExpressServer-->>Browser: Serve rendered HTML
Browser->>ExpressServer: Requests static assets (JS, CSS, etc.)
ExpressServer-->>Browser: Serves static files
Possibly related PRs
Poem
""" 📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate Unit Tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (3)
apps/frontend/src/server.ts (2)
26-31
: Consider security implications of long cache duration.Setting
maxAge: '1y'
for all static files may be too aggressive and could cause issues with cache invalidation during deployments.Consider a more conservative cache duration or implementing cache-busting strategies:
server.get( '*.*', express.static(distFolder, { - maxAge: '1y', + maxAge: '1d', // or implement proper cache-busting }) );
67-67
: Apply static analysis suggestion for optional chaining.The static analysis tool correctly identifies that optional chaining would be safer and more readable.
-const moduleFilename = (mainModule && mainModule.filename) || ''; +const moduleFilename = mainModule?.filename || '';apps/frontend/project.json (1)
53-68
: Consider expanding prerender routes for better SEO.The prerender target only includes the root route ("/"). For better SEO benefits, consider adding more static routes.
"options": { - "routes": ["/"] + "routes": ["/", "/about", "/contact"] // Add your static routes },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (8)
apps/frontend/project.json
(1 hunks)apps/frontend/src/app/app.config.server.ts
(1 hunks)apps/frontend/src/app/app.config.ts
(1 hunks)apps/frontend/src/main.server.ts
(1 hunks)apps/frontend/src/server.ts
(1 hunks)apps/frontend/tsconfig.server.json
(1 hunks)nx.json
(1 hunks)package.json
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/frontend/src/main.server.ts (1)
apps/frontend/src/app/app.config.server.ts (1)
config
(9-9)
apps/frontend/src/app/app.config.server.ts (1)
apps/frontend/src/app/app.config.ts (1)
appConfig
(9-15)
🪛 Biome (1.9.4)
apps/frontend/tsconfig.server.json
[error] 1-1: JSON standard does not allow comments.
(parse)
[error] 1-2: JSON standard does not allow comments.
(parse)
[error] 2-10: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
apps/frontend/src/server.ts
[error] 67-67: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (15)
nx.json (1)
66-68
: LGTM! Server target caching configuration is properly implemented.The addition of the "server" target default with caching enabled is appropriate for SSR builds and follows the same pattern as other target defaults in the workspace.
apps/frontend/tsconfig.server.json (1)
3-10
: Server TypeScript configuration is well-structured.The configuration properly extends the app config, sets appropriate compiler options for server-side code, and includes the correct entry point files for SSR.
apps/frontend/src/app/app.config.ts (1)
4-7
: Excellent addition of client hydration configuration.The
provideClientHydration(withEventReplay())
configuration is essential for SSR and properly implemented. Event replay ensures a smooth user experience by capturing and replaying events that occur before hydration completes.apps/frontend/src/app/app.config.server.ts (1)
1-9
: Excellent server configuration implementation following Angular Universal best practices.The server config correctly:
- Uses
mergeApplicationConfig
to combine base and server configurations- Adds
provideServerRendering()
for SSR capabilities- Maintains clean separation between client and server-specific providers
This pattern ensures consistent configuration across client and server environments.
package.json (5)
16-16
: Correct addition of Angular platform-server dependency.The
@angular/platform-server
dependency is essential for SSR and the version is consistent with other Angular dependencies.
18-18
: Good addition of Angular SSR package.The
@angular/ssr
package provides Angular's official SSR utilities and tooling support.
22-22
: Express dependency is appropriate for SSR server implementation.Express ^4.21.2 is a solid choice for the SSR server, providing a mature and well-supported web framework.
59-59
: Proper TypeScript support for Express.The
@types/express
dev dependency ensures proper TypeScript definitions for Express development.
65-65
: Browser-sync added for development workflow enhancement.Browser-sync is a useful development tool for live reloading and cross-device testing during SSR development.
apps/frontend/src/main.server.ts (1)
2-7
: Bootstrap function implementation looks correct.The server bootstrap setup follows Angular Universal patterns correctly with proper imports and function structure.
apps/frontend/src/server.ts (2)
34-47
: SSR route handler implementation is solid.The catch-all route properly configures the CommonEngine with appropriate providers and error handling.
52-70
: Server startup logic handles edge cases well.The webpack module detection and iisnode support show good consideration for different deployment scenarios.
apps/frontend/project.json (3)
27-37
: Server build target configuration is well-structured.The server target properly references the server entry point and TypeScript configuration with appropriate dependency management.
38-52
: SSR development server configuration is comprehensive.Both development and production configurations are properly set up with correct target references.
27-68
: Verify that required dependencies are installed.The new SSR targets require specific Angular Universal and Express dependencies. Ensure these are properly added to package.json.
#!/bin/bash # Description: Verify SSR dependencies are installed # Expected: All required packages should be present in package.json echo "Checking for required SSR dependencies..." cat package.json | jq -r '.dependencies, .devDependencies' | grep -E "(@angular/platform-server|@angular/ssr|express|@types/express)" || echo "Missing SSR dependencies!"
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ | ||
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove invalid JSON comments - this will cause parsing errors.
JSON standard doesn't allow comments. The TypeScript configuration will fail to parse with these comment lines.
Apply this diff to fix the parsing issue:
-/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
-/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
🧰 Tools
🪛 Biome (1.9.4)
[error] 1-1: JSON standard does not allow comments.
(parse)
[error] 1-2: JSON standard does not allow comments.
(parse)
🤖 Prompt for AI Agents
In apps/frontend/tsconfig.server.json at lines 1 to 2, remove the comment lines
because JSON does not support comments and these will cause parsing errors.
Delete both comment lines at the top of the file to ensure the JSON is valid and
can be parsed correctly by the TypeScript compiler.
@@ -0,0 +1,7 @@ | |||
import { bootstrapApplication } from '@angular/platform-browser'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect import for server-side rendering.
The import should be from @angular/platform-server
instead of @angular/platform-browser
for server-side rendering.
-import { bootstrapApplication } from '@angular/platform-browser';
+import { bootstrapApplication } from '@angular/platform-server';
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import { bootstrapApplication } from '@angular/platform-browser'; | |
import { bootstrapApplication } from '@angular/platform-server'; |
🤖 Prompt for AI Agents
In apps/frontend/src/main.server.ts at line 1, the import statement incorrectly
imports bootstrapApplication from '@angular/platform-browser'. For server-side
rendering, change the import source to '@angular/platform-server' to ensure
correct functionality.
Deploying devswhomove with
|
Latest commit: |
4cc0aa3
|
Status: | ✅ Deploy successful! |
Preview URL: | https://c00531eb.devswhomove.pages.dev |
Branch Preview URL: | https://feat-add-angular-ssr.devswhomove.pages.dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
.github/workflows/ci.yml (1)
30-30
: Add a descriptive step name for clarity.
Labeling steps improves CI log readability. Consider naming this install step:- - run: yarn install --frozen-lockfile + - name: Install dependencies + run: yarn install --frozen-lockfile
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
package-lock.json
is excluded by!**/package-lock.json
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (2)
.github/actions/nx-build/action.yml
(1 hunks).github/workflows/ci.yml
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- .github/actions/nx-build/action.yml
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/ci.yml
[error] 30-30: trailing spaces
(trailing-spaces)
🪛 GitHub Actions: CI
.github/workflows/ci.yml
[error] 1-1: nx format:check failed. Command exited with code 1 indicating formatting issues in the file.
View your CI Pipeline Execution ↗ for commit 4cc0aa3.
☁️ Nx Cloud last updated this comment at |
This pull request introduces server-side rendering (SSR) capabilities to the
frontend
application, enabling improved performance and SEO optimization. Key changes include the addition of SSR-specific configurations, new server files, and dependencies required for SSR functionality.SSR Implementation:
apps/frontend/project.json
: Added new targets (server
,serve-ssr
, andprerender
) to support server-side rendering and prerendering workflows.apps/frontend/src/server.ts
: Created an Express-based server setup to handle SSR, including static file serving and Angular engine integration.apps/frontend/src/app/app.config.server.ts
: Added a server-specific application configuration that merges with the existing client configuration.apps/frontend/src/main.server.ts
: Added a bootstrap file for initializing the server-side application.Dependency Updates:
package.json
: Added dependencies for SSR (@angular/platform-server
,@angular/ssr
,express
, and@types/express
) and development utilities likebrowser-sync
. [1] [2]Configuration Updates:
apps/frontend/tsconfig.server.json
: Created a TypeScript configuration file for server-side code, extending the existing application configuration.nx.json
: Added caching support for the newserver
target.These changes collectively enable server-side rendering for the application, providing a foundation for enhanced user experience and search engine visibility.
Summary by CodeRabbit
New Features
Chores