Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created April 27, 2020 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/495f06e258fb1c1e18637756f7a00f41 to your computer and use it in GitHub Desktop.
Save fitomad/495f06e258fb1c1e18637756f7a00f41 to your computer and use it in GitHub Desktop.
// MARK: - HTTP -
func routes(_ app: Application) throws {
...
///
app.post("login") { req -> HTTPStatus in
let login = try req.content.decode(LoginRequest.self)
...
// almacenamos valores en la sesion
req.session.data["nickname"] = login.nickname
req.session.data["room"] = login.roomName
...
}
}
// MARK: - WebSockets -
func webSockets(_ app: Application) throws
{
app.webSocket("chat") { request, ws in
...
// Recuperamos valores de la sesion.
let userName = request.session.data["nickname"] ?? "Usuario desconocido"
let room = request.session.data["room"] ?? "The Empty"
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment