Skip to content

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

Merged
merged 6 commits into from
Jun 22, 2025
Merged

feat: add ssr to the app #10

merged 6 commits into from
Jun 22, 2025

Conversation

santoshyadavdev
Copy link
Contributor

@santoshyadavdev santoshyadavdev commented Jun 22, 2025

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:

Dependency Updates:

  • package.json: Added dependencies for SSR (@angular/platform-server, @angular/ssr, express, and @types/express) and development utilities like browser-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 new server 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

    • Introduced server-side rendering (SSR) and prerendering capabilities for the frontend application.
    • Added a development server for SSR with support for both development and production environments.
    • Implemented client-side hydration with event replay for improved interactivity.
    • Added prerendering support for static routes.
  • Chores

    • Updated project dependencies to include Angular SSR, Express, and related tooling.
    • Added new configuration files and settings to support SSR and server builds.
    • Switched CI and workflow commands from npm to yarn for consistent dependency management.

Copy link

coderabbitai bot commented Jun 22, 2025

Caution

Review failed

The pull request is closed.

"""

Walkthrough

The 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

File(s) Change Summary
apps/frontend/project.json, nx.json Added SSR, server, and prerender build targets and caching configuration.
apps/frontend/src/app/app.config.server.ts, apps/frontend/src/main.server.ts Added server-specific Angular configuration and server bootstrap entry point.
apps/frontend/src/app/app.config.ts Added client hydration support to Angular app configuration.
apps/frontend/src/server.ts Added Express server for SSR with static file serving and Angular Universal rendering.
apps/frontend/tsconfig.server.json Added TypeScript configuration for server-side code compilation.
package.json Added Angular Universal, Express, type definitions, and live-reload dependencies for SSR support.
.github/actions/nx-build/action.yml Changed Nx CLI command runner from npx to yarn.
.github/workflows/ci.yml Changed CI package installation from npm ci to yarn install --frozen-lockfile.

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
Loading

Possibly related PRs

  • add ci #1: Modifies the CI workflow to switch from npm ci to yarn install --frozen-lockfile, affecting the same .github/workflows/ci.yml file.

Poem

🐇
The frontend hops with SSR delight,
Now servers render pages bright.
Express and Angular, side by side,
Hydration flows like a springtime tide.
Prerendered routes, a speedy quest—
The code is ready, fully blessed!

"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d67aad and 4cc0aa3.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • .github/workflows/ci.yml (1 hunks)
  • package.json (3 hunks)
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch feat/add-angular-ssr

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d22ba8 and 146fecb.

⛔ 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!"

Comment on lines +1 to +2
/* 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. */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.

Copy link

cloudflare-workers-and-pages bot commented Jun 22, 2025

Deploying devswhomove with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4cc0aa3
Status: ✅  Deploy successful!
Preview URL: https://c00531eb.devswhomove.pages.dev
Branch Preview URL: https://feat-add-angular-ssr.devswhomove.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 02bf384 and 1d67aad.

⛔ 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.

Copy link

nx-cloud bot commented Jun 22, 2025

View your CI Pipeline Execution ↗ for commit 4cc0aa3.

Command Status Duration Result
nx affected -t lint test build ✅ Succeeded 17s View ↗

☁️ Nx Cloud last updated this comment at 2025-06-22 14:43:02 UTC

@santoshyadavdev santoshyadavdev merged commit 0c12115 into main Jun 22, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant