Introduction
The portfolio application is configured with Angular Universal for server-side rendering (SSR). This provides significant benefits for SEO, initial page load performance, and social media sharing.Benefits of SSR for Portfolio
SEO Optimization
Search engines can crawl fully-rendered HTML content
Fast First Paint
Users see content immediately without waiting for JavaScript
Social Media
Rich previews work correctly on LinkedIn, Twitter, etc.
Performance
Improved Core Web Vitals and Lighthouse scores
Angular Universal Configuration
The SSR setup is configured inangular.json:
Key Configuration Options
outputMode: "server": Enables full SSR mode (vs static prerendering)server: "src/main.server.ts": Entry point for Angular server bootstrapssr.entry: "src/server.ts": Express server configuration file
Server Entry Point
The main server file is located atsrc/server.ts and uses Express with Angular SSR:
The
AngularNodeAppEngine is the core of Angular SSR. It handles rendering Angular components on the server and returning HTML to the client.Static File Serving
The server serves static assets with aggressive caching:Static files are cached for 1 year. Output hashing ensures that file names change when content changes, automatically invalidating old caches.
Request Handling
All non-static requests are handled by Angular:Server Bootstrap Configuration
The Angular server application is configured insrc/app/app.config.server.ts:
- Merges client-side and server-side application configs
- Provides server rendering capability with route support
- Uses separate server routes for SSR-specific behavior
Building for SSR
Install Dependencies
Ensure all SSR dependencies are installed:Key dependencies:
@angular/ssr- Angular SSR toolkit@angular/platform-server- Server platformexpress- Web server framework
Build the Application
Build both client and server bundles:This creates:
dist/portafolio/browser/- Client-side filesdist/portafolio/server/server.mjs- Server bundle
Running the SSR Server
The SSR server can be started with:Server Configuration
The server listens on:- Port: Environment variable
PORTor default4000 - Host: All interfaces (
0.0.0.0in production)
The server automatically detects if it’s the main module or running via PM2, making it compatible with process managers.
Production Deployment
Option 1: Direct Node.js
-
Build the application:
-
Copy
dist/portafolio/to your server -
Install production dependencies:
-
Start the server:
Option 2: PM2 Process Manager
-
Install PM2:
-
Start with PM2:
-
Configure auto-restart:
The server code includes PM2 detection (
process.env['pm_id']) and will start correctly when managed by PM2.Option 3: Docker
Create aDockerfile:
Adding API Endpoints
You can add custom API endpoints to the Express server. Editsrc/server.ts:
Troubleshooting
Server Won’t Start
- Check that port 4000 is not already in use
- Verify
dist/portafolio/server/server.mjsexists - Ensure Node.js 20+ is installed
Blank Page on Load
- Check browser console for errors
- Verify static files are served correctly (
/browserdirectory) - Test with
curl http://localhost:4000to see server response
Hydration Errors
- Ensure server and client render the same content
- Check for browser-only APIs used during SSR
- Review
app.routes.server.tsfor route conflicts
Use Chrome DevTools to view the full HTML source (not the rendered DOM) to verify SSR is working. The source should show complete page content before JavaScript executes.
Next Steps
- Configure reverse proxy (nginx) for production
- Set up SSL/TLS certificates
- Implement monitoring and logging
- Configure CDN for static assets
- Set up CI/CD pipeline for automated deployments