Issue
I am cherry picking the exact relevant piece of code from my Angular 16(now Angular 17) server.ts file.
import { ngExpressEngine } from '@nguniversal/express-engine';
server.engine(
'html',
ngExpressEngine({
bootstrap: AppServerModule,
})
);
Angular 17 no longer has the ngExpressEngine, and replacing with the new CommonEngine from angular/ssr does not work.
I am open to suggestions if anyone knows how to properly migrate. Thank you
Solution
I was able to use the syntax here to solve. Just swap out code in my question for code here
import { CommonEngine } from '@angular/ssr';
const commonEngine = new CommonEngine();
server.get('*', (req, res, next) => {
const { protocol, originalUrl, baseUrl, headers } = req;
commonEngine
.render({
bootstrap: AppServerModule,
documentFilePath: indexHtml,
url: `${protocol}://${headers.host}${originalUrl}`,
publicPath: distFolder,
providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }],
})
.then((html) => res.send(html))
.catch((err) => next(err));
});
Answered By - Charlie-Greenman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.