# Add Server-Side Rendering to an Angular App

Yes. Teammates can watch an agent add Angular SSR with hydration to a client-only app, guard its browser-only code, run the build and tests, and open a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/add-ssr/angular/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the application config before it adds a server. In an Angular 21 app shaped like realworld-apps/angular-realworld-example-app, angular.json uses the application builder with src/main.ts as the browser entry, dist/angular-conduit as the output, the theme stylesheet from the realworld git submodule, and src/_redirects copied into the output, the single-page fallback a static host needs. src/app/app.config.ts is zoneless, provides the router with lazy loadComponent routes from src/app/app.routes.ts, and provides HttpClient with three functional interceptors: apiInterceptor prefixes every request with the RealWorld API origin, tokenInterceptor adds the Token header, and errorInterceptor handles failures. Nothing in the project renders on a server today, and two deploy workflows assume that: deploy.yml zips dist/angular-conduit/browser into a release, and playwright.yml runs the e2e suite against the client build.

The browser-only code is the real work. src/app/core/auth/services/jwt.service.ts reads and writes window.localStorage directly, and app.config.ts runs an app initializer, initAuth, that calls getToken on startup and attaches a debug object to window; both would throw during a server render. The agent runs the ssr schematic to generate src/main.server.ts, src/server.ts with the Node request handler from the ssr package, src/app/app.config.server.ts and src/app/app.routes.server.ts, and adds provideClientHydration to app.config.ts. Then it makes JwtService check the platform through PLATFORM_ID before touching localStorage, has initAuth return EMPTY on the server so the first HTML renders the signed-out shell and the browser re-checks the token after hydration, and limits the debug object to the browser. The route guards in app.routes.ts read UserService.isAuthenticated and keep working because the server state is simply unauthenticated.

Render modes are chosen per route in app.routes.server.ts. The home page, tag pages and article pages render on the server, since they are the pages a crawler or a shared link hits; login and register can be prerendered because they are static forms; settings, the editor and the profile pages are client-rendered, because they depend on the reader's token. The agent writes that table into the pull request. angular.json gains the server entry, the ssr entry and the server output mode, so bun run build now produces dist/angular-conduit/server beside browser, and the agent runs node on the server bundle and requests the home page to see article markup in the raw HTML, which needs the public API to be reachable from the sandbox.

Proof is the repository's own commands plus one. The package manager is bun, with bun.lock and a setup script that initialises the submodule, so the agent runs bun run setup, bun run build, and bun run test, which is vitest through the analog Angular plugin with a jsdom environment from vitest.config.ts; the JwtService spec in src/app/core/auth/services is updated for the platform check. bun run format:check keeps prettier happy, as lint.yml requires. Then it runs the Playwright suite the way playwright.yml does, bun run test:e2e against the app, and screenshots the home page from the server bundle and from the client build so a teammate reading the run can compare the first paint before the pull request opens.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add server-side rendering with hydration to this Angular app. Read package.json, angular.json, tsconfig.app.json, vitest.config.ts, src/main.ts, src/index.html, src/_redirects, src/app/app.config.ts, src/app/app.routes.ts, every file under src/app/core/auth and src/app/core/interceptors, and .github/workflows/deploy.yml, lint.yml and playwright.yml first. Run bun run setup, then add the Angular SSR schematic with its Node server entry, server app config and server routes, and provideClientHydration in app.config.ts. Make JwtService safe on the server with a PLATFORM_ID check, have initAuth skip the token check and the window debug object on the server, and update the JwtService spec. Choose render modes per route: server for home, tag and article pages, prerender for login and register, client for settings, editor and profile, and explain the table in the pull request. Keep the existing client output path so deploy.yml still finds dist/angular-conduit/browser, and note in the pull request that the server bundle is not deployed by that workflow. Run bun run build, start the server bundle with node and request the home page to confirm rendered article markup, run bun run test, bun run format:check and bun run test:e2e, screenshot the home page from the server render and the client build, and open a pull request that quotes the build and test output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch that adds src/main.server.ts, src/server.ts, src/app/app.config.server.ts and src/app/app.routes.server.ts, edits angular.json, package.json, src/app/app.config.ts, src/app/core/auth/services/jwt.service.ts and its spec, and leaves src/_redirects and the deploy workflow as they were. The description carries the render-mode table, the reason each browser-only call was guarded, and the build, vitest and Playwright output from the sandbox, and it says plainly that deploy.yml still ships only the browser directory.

Session artifacts hold the two screenshots, server render and client build, each with a download URL that works for an hour without the key. The transcript keeps the raw HTML of the server-rendered home page with the article list in it, which is the whole point of the change, and the first failing vitest run of the JwtService spec before the platform check existed.

Before merging, a reviewer runs the server bundle locally, loads an article with scripts disabled to see the content, then enables them and signs in to confirm hydration did not double-render the header. They also decide how to host the server bundle, which is a deployment change the pull request names but does not make.

## Run it on every rendering request

Send this request when the team decides a client-only app needs server rendering, with the repository in resources. One sandbox holds the branch, the built server bundle and a browser, and everyone in the org can read the run as it works. The starter, or an org admin, sends corrections as follow-ups, for example moving the profile pages to server rendering, and the console queues one sent mid-turn. Taking the browser directly is a five-minute lease held by one person at a time.

When the turn finishes, the key's webhook receives run.completed or run.failed with data.session_url and data.events_url, for the runs that key started. The parked sandbox keeps node_modules, the submodule and the build, so a follow-up a day later rebuilds without a cold install.

## Why run it on Rush?

The failure in adding SSR is a window or localStorage call deep in a service that only throws when the server renders a particular route, and you find it by building the server bundle, starting it and requesting every route. That is a long loop on a laptop, especially with a submodule, a bun install and a Playwright suite in it. The agent runs the loop in its own sandbox with a browser and keeps the raw HTML of each server response, so a teammate can read the run and point at the route that still looks wrong.

The merge is still a person's. The pull request shows the render-mode table and the screenshots, the transcript shows each build, the vitest and Playwright runs and each follow-up that moved a route between modes. Nothing in the deploy workflow changes without the team asking.

## Frequently asked questions

### Will the app still deploy the way it does now?

Yes, as a client-only build. deploy.yml zips dist/angular-conduit/browser, and the agent keeps that path, so the existing release still works and still relies on src/_redirects for the single-page fallback. Serving the server bundle in dist/angular-conduit/server is a hosting change the pull request describes but does not make.

### What happens to the token stored in localStorage?

The server never sees it. JwtService checks PLATFORM_ID and returns no token on the server, initAuth returns EMPTY there, so the first HTML is the signed-out shell. After hydration the browser reads localStorage, calls getCurrentUser as before, and the header updates. A follow-up can move the token to a cookie if you want signed-in server renders.

### Which routes render on the server?

Home, tag and article pages, since they are what crawlers and shared links reach. Login and register are prerendered as static forms. Settings, the editor and the profile pages are client-rendered because their content depends on the reader's token. The table is in the pull request and any row can change in a follow-up.

### Does it need the public API during the build?

Only for the check, not for the build. The build itself does not call the API; the agent starts the server bundle afterwards and requests the home page, which fetches articles from the API origin set in apiInterceptor. If the sandbox cannot reach it, the pull request says so and shows the rendered shell instead.

## More Angular jobs

- [Add an Unsaved Changes Guard to an Angular App](https://getrush.ai/run/add-unsaved-changes-guard/angular/)
- [Dockerize an Angular App](https://getrush.ai/run/dockerize-app/angular/)
- [Find Dead Code in an Angular App](https://getrush.ai/run/find-dead-code/angular/)

## The same job on other stacks

- [Add Server-Side Rendering to a Lit Component](https://getrush.ai/run/add-ssr/lit/)

## More jobs like this: Steer a run as a team

- [Build an Admin Page in a Django App](https://getrush.ai/run/build-admin-page/django/)
- [Build an Admin Page in a Laravel App](https://getrush.ai/run/build-admin-page/laravel/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
