How to get feedback using Express and Angular?

I have a server written in Express that interacts with an application written in Angular on the client.

My express server receives a message from a third-party service to a route that will execute business logic, and then here I doubt a little better way forward.

After receiving the mail variables, I want to redirect the request to the Angular route, but I want to also make these received post variables available for the route.

Somehow, I want to be able to mix the res.json () and res.redirect () method, but I'm sure both of them complete the answer.

What would be a logical way to structure this?

Update: To expand on the problem, imagine that I have a route called / receivetransaction that receives some postback variables, including transaction ID, amount, etc. I want to execute business logic (save to the database) and then redirect the user to / thankyou (Angular route), but be able to access the data that was just received in the postback.

It seems like my best option is to save to the database and then send the transaction ID as JSON to the Angular view, which will then go to the database and pull the information. A bit inefficient, although (not a very big deal), but I would hope that there would be a different way around.

+4
source share
1 answer

I decided to do the following:

After the express route receives postback variables, it executes business logic (in particular, storing data in the database) and redirects the request to the angular route with the var request indicating the transaction identifier.

The angular controller uses $ location.search () to pull the transaction identifier from the var request, and from there it executes a request for an express API, which performs authentication and loads the relevant information into $ scope variables for transmission to the view.

0
source

All Articles