NotificationsMiddleware
struct NotificationsMiddleware : AsyncMiddleware, SiteControllerUtils
NotificationsMiddleware gets attached to Site routes, and periodically calls an API notification endpoint to get user notifications. The user notificaiton counts are then attached ot the user’s Session.
This setup is not ideal as a user with multiple Sessions on different devices may see different notificaitons at different times.
Currently this code breaks the UI/API layer separation somewhat by looking at the authenticated User. If we do need to build separate UI and API
servers, we can either:
* Stop inspecting the updatedAt
property; notificaitons will be sligihtly less realtime.
* Add a webSocket betwen the UI and API, pass usernames that have new notifications as they happen.
* Use Redis pub/sub
* Really, the communication is one-way – perhaps build a server endpoint in the UI code and the API layer acts as a client to call it?
Via any method, Vapor Sessions aren’t set up for finding sessions by user, or accessing any other Session at all, really.
-
Declaration
Swift
func registerRoutes(_ app: Application) throws
-
respond(to:
AsynchronouschainingTo: ) Declaration
Swift
func respond(to req: Request, chainingTo next: AsyncResponder) async throws -> Response