Skip to content
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
63c4b60
update deps, apply prettier, change to ESM, update tests
hrishikesh-k May 12, 2026
d723b43
update ci tests to use Node 22
hrishikesh-k May 13, 2026
a41c8f4
coderabbit 1
hrishikesh-k May 13, 2026
5228f75
remove exclude
hrishikesh-k May 13, 2026
a772d28
update lockfiles
hrishikesh-k May 13, 2026
aa3369d
lint fixes
hrishikesh-k May 13, 2026
a87042c
fix prettier config
hrishikesh-k May 13, 2026
f17a9b0
fix npm ci
hrishikesh-k May 13, 2026
2d4a587
coderabbit 2
hrishikesh-k May 13, 2026
0fed716
downgrade and pin angular
hrishikesh-k May 13, 2026
a4c1f7e
update engine version range to match Angular
hrishikesh-k May 13, 2026
49f5442
fix version and readme
hrishikesh-k May 13, 2026
8ee6796
update readme to suggest latest CLI
hrishikesh-k May 13, 2026
1967b06
add allowedHosts and trustedProxyHeaders
hrishikesh-k May 14, 2026
43517b0
Merge branch 'main' into hk/angular-22
hrishikesh-k May 14, 2026
e47da59
regenrate lockfiles
hrishikesh-k May 14, 2026
65c394d
fix type for getContext
hrishikesh-k May 15, 2026
766344a
update readme for deploy instructions
hrishikesh-k May 15, 2026
ed297f1
prevent missing env vars from failing build
hrishikesh-k May 15, 2026
306b642
fix for loop bug
hrishikesh-k May 15, 2026
a3cb3b7
update swapped file templates
hrishikesh-k May 15, 2026
fc84504
Merge branch 'main' into hk/angular-22
hrishikesh-k May 15, 2026
9877951
fix context potentially being undefined
hrishikesh-k May 15, 2026
74d27cc
consolidate app-engine exports in a single file
hrishikesh-k May 15, 2026
dc29e1a
conditionally update Angular config
hrishikesh-k May 15, 2026
846d7fc
revert pathname to request
hrishikesh-k May 15, 2026
35aa5cb
fix typo
hrishikesh-k May 15, 2026
065cff2
Merge branch 'main' into hk/angular-22
hrishikesh-k May 18, 2026
4a44694
fix merge conflicts
hrishikesh-k May 18, 2026
ca53395
Merge branch 'main' into hk/angular-22
hrishikesh-k May 18, 2026
285d979
match version of angular/ssr instead of core
hrishikesh-k May 18, 2026
5cafda5
Update README.md
hrishikesh-k May 18, 2026
d8af697
seperate version detection for angular/core and ssr
hrishikesh-k May 18, 2026
08952e1
update tests
hrishikesh-k May 18, 2026
095815b
update failBuild message and remove dead code
hrishikesh-k May 18, 2026
6058b19
Merge branch 'main' into hk/angular-22
hrishikesh-k May 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ export async function netlifyAppEngineHandler(request: Request): Promise<Respons

// Example API endpoints can be defined here.
// Uncomment and define endpoints as necessary.
// const pathname = new URL(request.url).pathname;
// if (pathname === '/api/hello') {
// if (context.url.pathname === '/api/hello') {
Comment thread
hrishikesh-k marked this conversation as resolved.
Outdated
// return Response.json({ message: 'Hello from the API' });
// }

Expand All @@ -147,14 +146,14 @@ If you are using Angular 19 and did not opt into the App Engine Developer Previe
```ts
import { CommonEngine } from '@angular/ssr/node'
import { render } from '@netlify/angular-runtime/common-engine.js'
import type { Context } from '@netlify/edge-functions'

const commonEngine = new CommonEngine()

export async function netlifyCommonEngineHandler(request: Request, context: any): Promise<Response> {
export async function netlifyCommonEngineHandler(request: Request, context: Context): Promise<Response> {
// Example API endpoints can be defined here.
// Uncomment and define endpoints as necessary.
// const pathname = new URL(request.url).pathname;
// if (pathname === '/api/hello') {
// if (context.url.pathname === '/api/hello') {
// return Response.json({ message: 'Hello from the API' });
// }

Expand All @@ -181,9 +180,7 @@ The [`server.ts` file](https://angular.dev/guide/ssr#configure-server-side-rende

### Requirements

To use the Angular Runtime while building and deploying with the CLI, you need to have `netlify-cli v26.0.0` installed (or a later version).

Please also make sure to use `ntl deploy --build` (rather than `ntl build && ntl deploy`).
Comment thread
hrishikesh-k marked this conversation as resolved.
To use the Angular Runtime while building and deploying with the CLI, you need to have `netlify-cli v26.0.0` installed (or a later version). To deploy the site via CLI, please use `netlify deploy`. Using `netlify deploy` with the `--no-build` flag is not supported.

## Getting Help

Expand Down
2,114 changes: 727 additions & 1,387 deletions demo/package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
},
"private": true,
"dependencies": {
"@angular/animations": "21.0.0",
"@angular/common": "21.0.0",
"@angular/compiler": "21.0.0",
"@angular/core": "21.0.0",
"@angular/forms": "21.0.0",
"@angular/platform-browser": "21.0.0",
"@angular/platform-browser-dynamic": "21.0.0",
"@angular/platform-server": "21.0.0",
"@angular/router": "21.0.0",
"@angular/ssr": "21.0.0",
"@angular/animations": "^21.2.11",
"@angular/common": "^21.2.11",
"@angular/compiler": "^21.2.11",
"@angular/core": "^21.2.11",
"@angular/forms": "^21.2.11",
"@angular/platform-browser": "^21.2.11",
"@angular/platform-browser-dynamic": "^21.2.11",
"@angular/platform-server": "^21.2.11",
"@angular/router": "^21.2.11",
"@angular/ssr": "^21.2.11",
"@netlify/angular-runtime": "file:..",
"@netlify/edge-functions": "^3.0.6",
"express": "^4.21.0",
Expand All @@ -29,9 +29,9 @@
"zone.js": "~0.15.0"
},
"devDependencies": {
"@angular/build": "21.0.0",
"@angular/cli": "21.0.0",
"@angular/compiler-cli": "21.0.0",
"@angular/build": "^21.2.11",
"@angular/cli": "^21.2.11",
"@angular/compiler-cli": "^21.2.11",
"@types/express": "^4.17.21",
"@types/jasmine": "~5.1.0",
"@types/node": "^22.0.0",
Expand Down
8 changes: 6 additions & 2 deletions demo/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { AngularAppEngine, createRequestHandler } from '@angular/ssr'
import { getAllowedHosts, getTrustProxyHeaders } from '@netlify/angular-runtime/app-engine-config.js'
import { getContext } from '@netlify/angular-runtime/context.js'

const angularAppEngine = new AngularAppEngine()
const angularAppEngine = new AngularAppEngine({
allowedHosts: getAllowedHosts(),
trustProxyHeaders: getTrustProxyHeaders(),
})

export const netlifyAppEngineHandler = async (request: Request): Promise<Response> => {
export async function netlifyAppEngineHandler(request: Request): Promise<Response> {
const context = getContext()

const result = await angularAppEngine.handle(request, context)
Expand Down
53 changes: 36 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
".": {
"default": "./src/index.js"
},
"./app-engine-config": {
"types": "./src/app-engine-config.d.ts",
"default": "./src/app-engine-config.js"
},
"./app-engine-config.js": {
"types": "./src/app-engine-config.d.ts",
"default": "./src/app-engine-config.js"
},
"./common-engine": {
"types": "./src/common-engine.d.ts",
"default": "./src/common-engine.js"
Expand Down Expand Up @@ -85,13 +93,14 @@
"node": "^22.22.0 || ^24.13.1 || >=26.0.0"
},
"devDependencies": {
"@opentelemetry/api": "~1.8.0",
"@netlify/build": "^35.13.5",
"@netlify/edge-functions": "^3.0.6",
Comment thread
hrishikesh-k marked this conversation as resolved.
Outdated
"@netlify/eslint-config-node": "^7.0.1",
"@opentelemetry/api": "~1.8.0",
"@types/node": "^24.0.0",
"eslint-plugin-unicorn": "^49.0.0",
"husky": "^9.1.7",
"netlify-cli": "^26.0.1",
"@netlify/build": "^35.13.5",
"npm-run-all2": "^8.0.4",
"prettier": "^3.8.3"
},
Expand Down
2 changes: 2 additions & 0 deletions src/app-engine-config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function getAllowedHosts(): string[]
export declare function getTrustProxyHeaders(): string[]
49 changes: 49 additions & 0 deletions src/app-engine-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { env } from 'node:process'

export function getAllowedHosts() {
const allowedHosts = []
const environmentVariables = ['DEPLOY_ID', 'DEPLOY_PRIME_URL', 'DEPLOY_URL', 'SITE_ID', 'SITE_NAME', 'URL']

for (const environmentVariable of environmentVariables) {
if (!env[environmentVariable] || env[environmentVariable] === 'undefined') {
console.warn(
`Missing Netlify-specific environment variable ${environmentVariable}. \`allowedHosts\` config might be incomplete.`,
)
return allowedHosts
}
}

const deployPrimeUrlHostname = new URL(env.DEPLOY_PRIME_URL).hostname

// <subdomain>.netlify.app OR <custom-domain>
// www handling is not required as Netlify will auto-redirect
allowedHosts.push(new URL(env.URL).hostname)
// <deploy-id>--<subdomain>.netlify.app
allowedHosts.push(new URL(env.DEPLOY_URL).hostname)
// <branch-name>--<subdomain>.netlify.app or <dp-#>--<subdomain>.netlify.app (supports ADS)
allowedHosts.push(deployPrimeUrlHostname)
// <subdomain>.netlify.app
// this will be duplicated for sites without custom domain
// but it's important to have in case a site's custom domain is removed after a deploy
allowedHosts.push(`${env.SITE_NAME}.netlify.app`)
// <site-id>.netlify.app
allowedHosts.push(`${env.SITE_ID}.netlify.app`)
// <deploy-id>--<site-id>.netlify.app
allowedHosts.push(`${env.DEPLOY_ID}--${env.SITE_ID}.netlify.app`)

// we need to extract the branch name or the deploy preview number
// so we can add the subdomain as well as site-id specific URLs
// this would be required for sites using ADS so that
// we can add netlify.app URLs as well
if (deployPrimeUrlHostname.includes('--')) {
const [branchNameOrDpNumber] = deployPrimeUrlHostname.split('--')
allowedHosts.push(`${branchNameOrDpNumber}--${env.SITE_NAME}.netlify.app`)
allowedHosts.push(`${branchNameOrDpNumber}--${env.SITE_ID}.netlify.app`)
}

return allowedHosts
}

export function getTrustProxyHeaders() {
return ['x-forwarded-for']
}
4 changes: 3 additions & 1 deletion src/context.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export declare function getContext(): any
import type { Context } from '@netlify/edge-functions'

export declare function getContext(): Context | undefined
6 changes: 3 additions & 3 deletions src/helpers/serverModuleHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ export async function fixServerTs({ angularVersion, siteRoot, failPlugin, failBu
const angularRuntimeVersionInstalledByUser = await getAngularRuntimeVersion(siteRoot)
if (!angularRuntimeVersionInstalledByUser) {
failBuild(
"Angular@19 SSR on Netlify requires '@netlify/angular-runtime' version 2.2.0 or later to be installed. Please install it and try again.",
`Angular@${angularVersion} SSR on Netlify requires '@netlify/angular-runtime' version 2.2.0 or later to be installed. Please install it and try again.`,
)
} else if (!satisfies(angularRuntimeVersionInstalledByUser, '>=2.2.0', { includePrerelease: true })) {
failBuild(
`Angular@19 SSR on Netlify requires '@netlify/angular-runtime' version 2.2.0 or later to be installed. Found version "${angularRuntimeVersionInstalledByUser}". Please update it to version 2.2.0 or later and try again.`,
`Angular@${angularVersion} SSR on Netlify requires '@netlify/angular-runtime' version 2.2.0 or later to be installed. Found version "${angularRuntimeVersionInstalledByUser}". Please update it to version 2.2.0 or later and try again.`,
)
}
Comment thread
hrishikesh-k marked this conversation as resolved.

// check whether project is using stable CommonEngine or Developer Preview AppEngine
// check whether project is using CommonEngine or AppEngine
const serverModuleContents = await readFile(serverModuleLocation, 'utf8')

const usedEngineBasedOnKnownSignatures = getEngineBasedOnKnownSignatures(serverModuleContents)
Expand Down
14 changes: 12 additions & 2 deletions src/helpers/setUpEdgeFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,23 @@ export async function setUpEdgeFunction({ outputPath, constants, failBuild, used
toPosix,
)

// buy putting this into a separate module that's imported first,
// by putting this into a separate module that's imported first,
// we ensure this is initialised before any other module
const polyfills = `
import process from "node:process"

globalThis.process = process
globalThis.DenoEvent = globalThis.Event // storing this for fixup-event.mjs
globalThis.process = process

// setting \`undefined\` as environment variable is not allowed: https://nodejs.org/api/process.html#processenv
// so we set it as a string ourselves

globalThis.process.env.DEPLOY_ID = ${JSON.stringify(env.DEPLOY_ID ?? 'undefined')}
globalThis.process.env.DEPLOY_PRIME_URL = ${JSON.stringify(env.DEPLOY_PRIME_URL ?? 'undefined')}
globalThis.process.env.DEPLOY_URL = ${JSON.stringify(env.DEPLOY_URL ?? 'undefined')}
globalThis.process.env.SITE_ID = ${JSON.stringify(env.SITE_ID ?? 'undefined')}
globalThis.process.env.SITE_NAME = ${JSON.stringify(env.SITE_NAME ?? 'undefined')}
globalThis.process.env.URL = ${JSON.stringify(env.URL ?? 'undefined')}
`

// angular's polyfills override the global `Event` with a custom implementation.
Expand Down
Loading