Skip to content

Commit 7fe10d0

Browse files
committed
feat: adjust adapter for angular@19
1 parent 3560175 commit 7fe10d0

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

demo/src/app/dashboard/dashboard.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, Inject, OnInit, Optional } from '@angular/core'
22
import { Hero } from '../hero'
33
import { HeroService } from '../hero.service'
44
import { RouterModule } from '@angular/router'
5-
import type { Context } from '@netlify/edge-functions'
5+
import { REQUEST, REQUEST_CONTEXT } from '@angular/ssr/tokens'
66

77
@Component({
88
selector: 'app-dashboard',
@@ -16,8 +16,8 @@ export class DashboardComponent implements OnInit {
1616

1717
constructor(
1818
private heroService: HeroService,
19-
@Inject('netlify.request') @Optional() request?: Request,
20-
@Inject('netlify.context') @Optional() context?: Context,
19+
@Inject(REQUEST) @Optional() request?: Request,
20+
@Inject(REQUEST_CONTEXT) @Optional() context?: any,
2121
) {
2222
if (request) {
2323
console.log(

src/helpers/setUpEdgeFunction.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const getPrerenderedRoutes = async (outputDir) => {
5454
const file = join(outputDir, 'prerendered-routes.json')
5555
if (!existsSync(file)) return []
5656
const { routes: prerenderedRoutes } = await readJson(file)
57+
58+
// angular@19 returns an object with routes as keys
59+
if (!Array.isArray(prerenderedRoutes)) return Object.keys(prerenderedRoutes)
60+
5761
return prerenderedRoutes
5862
}
5963

@@ -103,22 +107,15 @@ const setUpEdgeFunction = async ({ angularJson, constants, failBuild }) => {
103107

104108
const ssrFunction = `
105109
import "./polyfill.mjs";
106-
import { Buffer } from "node:buffer";
107-
import { renderApplication } from "${toPosix(relative(edgeFunctionDir, serverDistRoot))}/render-utils.server.mjs";
108-
import bootstrap from "${toPosix(relative(edgeFunctionDir, serverDistRoot))}/main.server.mjs";
110+
import { ɵgetOrCreateAngularServerApp as getOrCreateAngularServerApp } from "${toPosix(
111+
relative(edgeFunctionDir, serverDistRoot),
112+
)}/main.server.mjs";
109113
import "./fixup-event.mjs";
110114
111-
const document = Buffer.from(${JSON.stringify(
112-
Buffer.from(html, 'utf-8').toString('base64'),
113-
)}, 'base64').toString("utf-8");
115+
const app = getOrCreateAngularServerApp()
114116
115117
export default async (request, context) => {
116-
const html = await renderApplication(bootstrap, {
117-
url: request.url,
118-
document,
119-
platformProviders: [{ provide: "netlify.request", useValue: request }, { provide: "netlify.context", useValue: context }],
120-
});
121-
return new Response(html, { headers: { "content-type": "text/html" } });
118+
return await app.render(request, context)
122119
};
123120
124121
export const config = {

0 commit comments

Comments
 (0)