Route lifecycle events such as route:BeforeComplete
Key Takeaway
Save user-submitted data, such as form data, in a route:BeforeComplete listener. The event fires after all middleware steps have run but before route:Complete renders the response.
In SFRA, the server module runs each controller route as a chain of steps and emits named events as the chain moves forward. You can subscribe to these route lifecycle events, such as route:BeforeComplete, to run code at a fixed point in the request without rewriting the route. When you know the order of the events, you know where work such as saving form data belongs.
How a route runs
Every SFRA controller requires the server module. The server module registers routes and emits an event at every step of running them.
A route is a chain of functions. In server.get or server.post, the route name comes first and the main function comes last. Any middleware functions sit in between. Each step must call next() at its end, or the next function in the chain doesn't run.