Skip to content
This repository has been 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

Open
Avcajaraville opened this issue Jul 17, 2019 · 0 comments
Open

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

Avcajaraville opened this issue Jul 17, 2019 · 0 comments

Comments

@Avcajaraville
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant