3

I have a launcher site that launches different Angular2 apps I own (possibly on different domains) and want to pass in configuration details via a request body. Is it possible to send a POST request to an angular2 app so that I can send body data? And if so how do I implement a component? listener? router? to accept this data?

Felix
  • 610
  • 2
  • 9
  • 21
  • 1
    I think this question is too broad for SO. You can't send a POST request to an app running in the browser. The browser (also the Angular app) can send POST requests to the server. – Günter Zöchbauer Sep 07 '16 at 17:57
  • What if it's sending the POST request to initially load the app (before it starts running)? is there a way for maybe the top most app.component to accept data in the constructor or onInit or something? – Felix Sep 07 '16 at 19:03
  • Loading the app in an iframe from the launcher* – Felix Sep 07 '16 at 19:12

1 Answers1

0

You can pass the data as query params of the application url and then use the angular2 router inside that application to extract the data.

See if this helps: https://angular.io/docs/ts/latest/guide/router.html#!#query-parameters

sessionId = this.route.queryParams.map(params => params['session_id'] || 'None');
Luis Cazacu
  • 186
  • 4
  • Thanks Luis. I may end up using params, however, the objective is to hide data from the URL so it's not being logged - hence sending it via the body when loading the app. I'm not sure if this is possible though. – Felix Sep 07 '16 at 19:01
  • @Felix If you have access to the server side of the code that serves your application you could inject stuff in your html or js code before returning it. Another option is to encrypt your query string to hide the data. – Luis Cazacu Sep 07 '16 at 20:12
  • Unfortunately it's serverless implementation (AWS) =/ – Felix Sep 07 '16 at 20:19
  • @Felix then probably encoding your query string in base64 could be an alternative http://stackoverflow.com/questions/12102670/php-form-example-which-will-encrypt-query-string-get-data-hiding-rather-tha – Luis Cazacu Sep 07 '16 at 20:22
  • Thanks Luis, I'll take a look into this solution. – Felix Sep 07 '16 at 20:28