Skip to content

Commit

Permalink
Merge branch 'release-2211.20.1' into fix/CXSPA-6438
Browse files Browse the repository at this point in the history
  • Loading branch information
rmch91 authored Mar 12, 2024
2 parents d569e66 + 8719a7d commit 8ab9444
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export function app(): express.Express {
const server = express();
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
const browserDistFolder = resolve(serverDistFolder, '../browser');
const indexHtml = join(serverDistFolder, 'index.server.html');
const indexHtml = join(browserDistFolder, 'index.html');
server.set('trust proxy', 'loopback');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function app(): express.Express {
const server = express();
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
const browserDistFolder = resolve(serverDistFolder, '../browser');
const indexHtml = join(serverDistFolder, 'index.server.html');
const indexHtml = join(browserDistFolder, 'index.html');

server.set('trust proxy', 'loopback');

Expand Down
29 changes: 29 additions & 0 deletions projects/schematics/src/add-ssr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,34 @@ function prepareDependencies(): NodeDependency[] {
return spartacusDependencies.concat(thirdPartyDependencies);
}

/**
* Adds `build:ssr` script to `package.json` as it's required for CCv2 build - process fails when script is missing.
*
* TODO: CXSPA-6466 Can be removed if Model T adjust their build process to not require this script.
*/
function addBuildSsrScript(spartacusOptions: SpartacusOptions): Rule {
return (tree: Tree, context: SchematicContext) => {
if (spartacusOptions.debug) {
context.logger.info(
`⌛️ Adding "build:ssr" script to "package.json"... (CCv2 purposes)`
);
}
const pkgPath = '/package.json';
const pkg = tree.readJson(pkgPath) as {
scripts?: Record<string, string>;
} | null;
if (pkg === null) {
throw new SchematicsException('Could not find package.json');
}
pkg.scripts = {
...pkg.scripts,
'build:ssr': 'ng build',
};

tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2));
};
}

/**
* Fixes the configuration for SSR and Prerendering to be able to work with Spartacus.
*/
Expand Down Expand Up @@ -467,6 +495,7 @@ export function addSSR(options: SpartacusOptions): Rule {
externalSchematic(ANGULAR_SSR, 'ng-add', {
project: options.project,
}),
addBuildSsrScript(options),
modifyAppServerModuleFile(),
removeClientHydration(options),
modifyIndexHtmlFile(options),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ exports[`Spartacus Schematics: ng-add should add spartacus properly with SSR 2`]
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"serve:ssr:schematics-test": "node dist/schematics-test/server/server.mjs"
"serve:ssr:schematics-test": "node dist/schematics-test/server/server.mjs",
"build:ssr": "ng build"
},
"private": true,
"dependencies": {
Expand Down

0 comments on commit 8ab9444

Please sign in to comment.