How to set providers in Angular v19 SSR?

Discussão em 'Angular' iniciado por Sergej, Novembro 20, 2024.

  1. Sergej

    Sergej Guest

    In Angular <19 I used such code to specify the providers:

    // All regular routes use the Angular engine
    server.get('**', (req, res, next) => {
    const { protocol, originalUrl, baseUrl, headers } = req;

    commonEngine
    .render({
    bootstrap,
    documentFilePath: indexHtml,
    url: `${protocol}://${headers.host}${originalUrl}`,
    publicPath: distFolder,
    providers: [
    { provide: APP_BASE_HREF, useValue: baseUrl },
    { provide: RESPONSE, useValue: res },
    { provide: REQUEST, useValue: req },
    ],
    })
    .then((html) => res.send(html))
    .catch((err) => next(err));
    });


    but in Angular 19 there is another structure:

    app.use('/**', (req, res, next) => {
    angularApp
    .handle(req)
    .then((response) =>
    response ? writeResponseToNodeResponse(response, res) : next(),
    )
    .catch(next);
    });


    I have tried to add the providers array in the second parameter of handle() method, but it did not work for me.

    I need to set providers for the REQUEST token, which should be the req object

    Continue reading...

Compartilhe esta Página