Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Is there any way of doing a post request WITHOUT javascript ? #685

@Avcajaraville

Description

@Avcajaraville

A use case I have for server side rendering are clients that, for some reason, don't have javascript available.

All get requests work fine in SSR, but Im not able to make a post request using SSR.

As an example, say I have these routes on express:

app.post('/api/login', (req, res, next) => {
  res.locals.login = true;
  next();
});

app.get('*', (req, res) => {
  res.render(
    'index',
    {
      req,
      res,
      providers: [
        {
          provide: 'REQUEST',
          useValue: req,
        },
        {
          provide: 'RESPONSE',
          useValue: res,
        },
      ],
    },
    (err, html) => {
      console.log(`GET: ${req.originalUrl}`);
      if (!!err) throw err;
      res.send(html);
    }
  );
});

I have my components injected with the RESPONSE service, and accessing it like:

import { RESPONSE } from '@nguniversal/express-engine/tokens';

constructor(@Inject(RESPONSE) private response: any) {
  this.response.locals // undefined
}

Any way I can access the res.locals on my angular component via server side when performing a classic POST request ?

Im using a form element, with action and post correctly set, code is just orientative.

Im afraid this might not be posible without an ajax request. Is this the case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions