From: asonix Date: Mon, 20 Apr 2020 15:25:47 +0000 (-0500) Subject: Add websockets into the api scope X-Git-Url: http://these/git/%7B%60%24%7BarchiveUrl%7D/static/%24%7Bargs.pageFn.jump%20n%7D?a=commitdiff_plain;h=db4454b52b8e8f71d35ca2b874ee279ed49a5317;p=lemmy.git Add websockets into the api scope --- diff --git a/server/src/main.rs b/server/src/main.rs index 6abb2243..c92770f2 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -8,7 +8,7 @@ use diesel::r2d2::{ConnectionManager, Pool}; use diesel::PgConnection; use lemmy_server::{ rate_limit::{rate_limiter::RateLimiter, RateLimit}, - routes::{api, federation, feeds, index, nodeinfo, webfinger, websocket}, + routes::{api, federation, feeds, index, nodeinfo, webfinger}, settings::Settings, websocket::server::*, }; @@ -59,7 +59,6 @@ async fn main() -> io::Result<()> { .configure(index::config) .configure(nodeinfo::config) .configure(webfinger::config) - .configure(websocket::config) // static files .service(actix_files::Files::new( "/static", diff --git a/server/src/routes/api.rs b/server/src/routes/api.rs index 3ef8ca51..025c6e0a 100644 --- a/server/src/routes/api.rs +++ b/server/src/routes/api.rs @@ -10,6 +10,8 @@ use actix_web::guard; pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { cfg.service( web::scope("/api/v1") + // Websockets + .service(web::resource("/ws").to(super::websocket::chat_route)) // Site .service( web::scope("/site") diff --git a/server/src/routes/websocket.rs b/server/src/routes/websocket.rs index c6bca9aa..eb157590 100644 --- a/server/src/routes/websocket.rs +++ b/server/src/routes/websocket.rs @@ -2,17 +2,13 @@ use super::*; use crate::websocket::server::*; use actix_web::{Error, Result}; -pub fn config(cfg: &mut web::ServiceConfig) { - cfg.service(web::resource("/api/v1/ws").to(chat_route)); -} - /// How often heartbeat pings are sent const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5); /// How long before lack of client response causes a timeout const CLIENT_TIMEOUT: Duration = Duration::from_secs(10); /// Entry point for our route -async fn chat_route( +pub async fn chat_route( req: HttpRequest, stream: web::Payload, chat_server: web::Data>,