From 731a4bfa2caf0c2c611ab9ca8dbf7834f3320ad2 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Wed, 30 Aug 2023 12:15:28 +0100 Subject: [PATCH] fix(angular): use the correct output path for mf ssr #18849 --- .../generators/host/__snapshots__/host.spec.ts.snap | 4 ++-- .../generators/host/files/src/main.server.ts__tmpl__ | 2 +- packages/angular/src/generators/host/lib/add-ssr.ts | 6 ++++++ .../remote/__snapshots__/remote.spec.ts.snap | 4 ++-- .../remote/files/base/src/main.server.ts__tmpl__ | 4 ++-- packages/angular/src/generators/remote/lib/add-ssr.ts | 11 +++++++++++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap b/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap index a8c1a5cf82a78..a3562d04943c1 100644 --- a/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap +++ b/packages/angular/src/generators/host/__snapshots__/host.spec.ts.snap @@ -51,7 +51,7 @@ import { AppServerModule } from './bootstrap.server'; // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/test/browser'); + const browserBundles = join(process.cwd(), 'dist/test/browser'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) @@ -223,7 +223,7 @@ import bootstrap from './bootstrap.server'; // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/test/browser'); + const browserBundles = join(process.cwd(), 'dist/test/browser'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) diff --git a/packages/angular/src/generators/host/files/src/main.server.ts__tmpl__ b/packages/angular/src/generators/host/files/src/main.server.ts__tmpl__ index 18327a24df28a..905a0fd39a60f 100644 --- a/packages/angular/src/generators/host/files/src/main.server.ts__tmpl__ +++ b/packages/angular/src/generators/host/files/src/main.server.ts__tmpl__ @@ -12,7 +12,7 @@ import<% if(standalone) { %> bootstrap <% } else { %> { AppServerModule } <% } % // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/<%= appName %>/browser'); + const browserBundles = join(process.cwd(), '<%= browserBundleOutput %>'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) diff --git a/packages/angular/src/generators/host/lib/add-ssr.ts b/packages/angular/src/generators/host/lib/add-ssr.ts index 85c519cba85a9..452da0af06f51 100644 --- a/packages/angular/src/generators/host/lib/add-ssr.ts +++ b/packages/angular/src/generators/host/lib/add-ssr.ts @@ -35,8 +35,14 @@ export async function addSsr(tree: Tree, options: Schema, appName: string) { "import('./src/main.server');" ); + const browserBundleOutput = joinPathFragments( + project.targets.build.options.outputPath, + 'browser' + ); + generateFiles(tree, join(__dirname, '../files'), project.root, { appName, + browserBundleOutput, standalone: options.standalone, tmpl: '', }); diff --git a/packages/angular/src/generators/remote/__snapshots__/remote.spec.ts.snap b/packages/angular/src/generators/remote/__snapshots__/remote.spec.ts.snap index 468ffefb7530a..d4616f812880f 100644 --- a/packages/angular/src/generators/remote/__snapshots__/remote.spec.ts.snap +++ b/packages/angular/src/generators/remote/__snapshots__/remote.spec.ts.snap @@ -60,8 +60,8 @@ import { AppServerModule } from './bootstrap.server'; // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/test/browser'); - const serverBundles = join(process.cwd(), 'dist/apps/test/server'); + const browserBundles = join(process.cwd(), 'dist/test/browser'); + const serverBundles = join(process.cwd(), 'dist/test/server'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) diff --git a/packages/angular/src/generators/remote/files/base/src/main.server.ts__tmpl__ b/packages/angular/src/generators/remote/files/base/src/main.server.ts__tmpl__ index a35272773bdd6..2551ff8dd4977 100644 --- a/packages/angular/src/generators/remote/files/base/src/main.server.ts__tmpl__ +++ b/packages/angular/src/generators/remote/files/base/src/main.server.ts__tmpl__ @@ -12,8 +12,8 @@ import<% if(standalone) { %> bootstrap <% } else { %> { AppServerModule } <% } % // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); - const browserBundles = join(process.cwd(), 'dist/apps/<%= appName %>/browser'); - const serverBundles = join(process.cwd(), 'dist/apps/<%= appName %>/server'); + const browserBundles = join(process.cwd(), '<%= browserBundleOutput %>'); + const serverBundles = join(process.cwd(), '<%= serverBundleOutput %>'); server.use(cors()); const indexHtml = existsSync(join(browserBundles, 'index.original.html')) diff --git a/packages/angular/src/generators/remote/lib/add-ssr.ts b/packages/angular/src/generators/remote/lib/add-ssr.ts index ac404035fab5f..ff388769457b6 100644 --- a/packages/angular/src/generators/remote/lib/add-ssr.ts +++ b/packages/angular/src/generators/remote/lib/add-ssr.ts @@ -41,12 +41,23 @@ export async function addSsr( "import('./src/main.server');" ); + const browserBundleOutput = joinPathFragments( + project.targets.build.options.outputPath, + 'browser' + ); + const serverBundleOutput = joinPathFragments( + project.targets.build.options.outputPath, + 'server' + ); + generateFiles( tree, joinPathFragments(__dirname, '../files/base'), project.root, { appName, + browserBundleOutput, + serverBundleOutput, standalone, tmpl: '', }