     }
 
     func build(_ builder: RouteBuilder) throws {
-        builder.get {req in
-            guard req.auth.isAuthenticated(User.self) else { return Response(redirect: "/users/login") }
+        try addViewRoutes(builder)
+        try addApiRoutes(builder)
 
-            return Response(redirect: "/wall")
+        builder.socket("ws") {req, ws in
+            Gateway.shared.add(ws)
+
+            ws.onClose = {ws, code, reason, clean in
+                Gateway.shared.remove(ws)
+            }
         }
+    }
 
-        builder.grouped(passwordProtect).get("wall") {req in
-            return try self.view.make("post.html")
-        }
-
+    private func addApiRoutes(_ builder: RouteBuilder) throws {
         builder.grouped("api").grouped(passwordProtect).group("post") {postGroup in
             postGroup.post(handler: PostController.create)
         }

            userGroup.post("new", handler: UserController.create)
            userGroup.grouped(passwordProtect).post("login", handler: UserController.login)
            userGroup.post("logout", handler: UserController.logout)
        }

        builder.group("users") {userGroup in

                return try self.view.make("users/logout.html")
            }
        }
    }
}
