Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 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
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
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ If you are using Angular 20 or Angular 19 with App Engine Developer Preview:

```ts
import { AngularAppEngine, createRequestHandler } from '@angular/ssr'
import { getContext } from '@netlify/angular-runtime/context.js'
import { getContext } from '@netlify/angular-runtime/app-engine.js'

const angularAppEngine = new AngularAppEngine()

Expand All @@ -127,7 +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;
// const pathname = new URL(request.url.pathname)
// if (pathname === '/api/hello') {
// return Response.json({ message: 'Hello from the API' });
// }
Expand All @@ -153,7 +153,7 @@ const commonEngine = new CommonEngine()
export async function netlifyCommonEngineHandler(request: Request, context: any): Promise<Response> {
// Example API endpoints can be defined here.
// Uncomment and define endpoints as necessary.
// const pathname = new URL(request.url).pathname;
// const pathname = new URL(request.url).pathname
// if (pathname === '/api/hello') {
// return Response.json({ message: 'Hello from the API' });
// }
Expand Down Expand Up @@ -181,9 +181,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 changes: 1 addition & 1 deletion context.d.ts → app-engine.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This is duplicating module resolution from package.json#exports
// because some module resolution settings in tsconfig.json are not honoring export maps
// https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution
export * from './src/context.js'
export * from './src/app-engine.js'
2 changes: 1 addition & 1 deletion context.js → app-engine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This is duplicating module resolution from package.json#exports
// because some module resolution settings in tsconfig.json are not honoring export maps
// https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution
export * from './src/context.js'
export * from './src/app-engine.js'
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
9 changes: 6 additions & 3 deletions demo/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { AngularAppEngine, createRequestHandler } from '@angular/ssr'
import { getContext } from '@netlify/angular-runtime/context.js'
import { getAllowedHosts, getContext, getTrustProxyHeaders } from '@netlify/angular-runtime/app-engine.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.

25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"src/**/*.js",
"src/**/*.json",
"src/**/*.d.ts",
"context.js",
"context.d.ts",
"app-engine.js",
"app-engine.d.ts",
"common-engine.js",
"common-engine.d.ts",
"manifest.yml"
Expand All @@ -20,21 +20,21 @@
".": {
"default": "./src/index.js"
},
"./app-engine": {
"types": "./src/app-engine.d.ts",
"default": "./src/app-engine.js"
},
"./app-engine.js": {
"types": "./src/app-engine.d.ts",
"default": "./src/app-engine.js"
},
"./common-engine": {
"types": "./src/common-engine.d.ts",
"default": "./src/common-engine.js"
},
"./common-engine.js": {
"types": "./src/common-engine.d.ts",
"default": "./src/common-engine.js"
},
"./context": {
"types": "./src/context.d.ts",
"default": "./src/context.js"
},
"./context.js": {
"types": "./src/context.d.ts",
"default": "./src/context.js"
}
},
"scripts": {
Expand Down Expand Up @@ -85,13 +85,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",
"@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
5 changes: 5 additions & 0 deletions src/app-engine.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Context } from '@netlify/edge-functions'

export declare function getAllowedHosts(): string[]
export declare function getContext(): Context | undefined
export declare function getTrustProxyHeaders(): string[]
54 changes: 54 additions & 0 deletions src/app-engine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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`)
}
Comment thread
hrishikesh-k marked this conversation as resolved.

return allowedHosts
}

export function getContext() {
// eslint-disable-next-line no-undef
return typeof Netlify !== 'undefined' ? Netlify?.context : undefined
}

export function getTrustProxyHeaders() {
return ['x-forwarded-for']
}
1 change: 0 additions & 1 deletion src/context.d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/context.js

This file was deleted.

Loading
Loading