Skip to content

Commit

Permalink
remove socketioxide
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplanelad committed Nov 25, 2024
1 parent d92fa8f commit eb78d7f
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 215 deletions.
5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ auth_jwt = ["dep:jsonwebtoken"]
cli = ["dep:clap"]
testing = ["dep:axum-test"]
with-db = ["dep:sea-orm", "dep:sea-orm-migration", "loco-gen/with-db"]
channels = ["dep:socketioxide"]
# Storage features
all_storage = ["storage_aws_s3", "storage_azure", "storage_gcp"]
storage_aws_s3 = ["object_store/aws"]
Expand Down Expand Up @@ -120,10 +119,6 @@ cfg-if = "1"

uuid = { version = "1.10.0", features = ["v4", "fast-rng"] }

# A socket.io server implementation
socketioxide = { version = "0.14.0", features = ["state"], optional = true }


# File Upload
object_store = { version = "0.11.0", default-features = false }

Expand Down
87 changes: 0 additions & 87 deletions docs-site/content/docs/extras/channels.md

This file was deleted.

19 changes: 19 additions & 0 deletions docs-site/content/docs/extras/websocket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
+++
title = "Websocket"
description = ""
date = 2024-01-21T18:20:00+00:00
updated = 2024-01-21T18:20:00+00:00
draft = false
weight = 2
sort_by = "weight"
template = "docs/page.html"

[extra]
lead = ""
toc = true
top = false
flair =[]
+++

## Chat Room Example
For a simple example of a chat room implementation with [socketioxide](https://github.com/Totodore/socketioxide), refer to this [link](https://github.com/loco-rs/chat-rooms).
1 change: 0 additions & 1 deletion docs-site/content/docs/getting-started/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ Here's a rundown of what Loco creates for you by default:
| `tasks/` | Contains your day to day business-oriented tasks such as sending emails, producing business reports, db maintenance, etc. |
| `tests/` | Your app-wide tests: models, requests, etc. |
| `config/` | A stage-based configuration folder: development, test, production |
| `channels/` | Contains all channels routes. |
## Hello, Loco!
Expand Down
6 changes: 0 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use std::{net::SocketAddr, sync::Arc};
use async_trait::async_trait;
use axum::Router as AxumRouter;

#[cfg(feature = "channels")]
use crate::controller::channels::AppChannels;
use crate::{
bgworker::{self, Queue},
boot::{shutdown_signal, BootResult, ServeParams, StartMode},
Expand Down Expand Up @@ -192,10 +190,6 @@ pub trait Hooks: Send {
Ok(ctx)
}

#[cfg(feature = "channels")]
/// Register channels endpoints to the application routers
fn register_channels(_ctx: &AppContext) -> AppChannels;

/// Connects custom workers to the application using the provided
/// [`Processor`] and [`AppContext`].
async fn connect_workers(ctx: &AppContext, queue: &Queue) -> Result<()>;
Expand Down
47 changes: 0 additions & 47 deletions src/controller/app_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use std::{fmt, sync::OnceLock};
use axum::Router as AXRouter;
use regex::Regex;

#[cfg(feature = "channels")]
use super::channels::AppChannels;
use crate::{
app::{AppContext, Hooks},
controller::{middleware::MiddlewareLayer, routes::Routes},
Expand All @@ -26,8 +24,6 @@ fn get_normalize_url() -> &'static Regex {
pub struct AppRoutes {
prefix: Option<String>,
routes: Vec<Routes>,
#[cfg(feature = "channels")]
channels: Option<AppChannels>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -67,8 +63,6 @@ impl AppRoutes {
Self {
prefix: None,
routes: vec![],
#[cfg(feature = "channels")]
channels: None,
}
}

Expand Down Expand Up @@ -158,13 +152,6 @@ impl AppRoutes {
self
}

#[cfg(feature = "channels")]
#[must_use]
pub fn add_app_channels(mut self, channels: AppChannels) -> Self {
self.channels = Some(channels);
self
}

#[must_use]
pub fn middlewares<H: Hooks>(&self, ctx: &AppContext) -> Vec<Box<dyn MiddlewareLayer>> {
H::middlewares(ctx)
Expand Down Expand Up @@ -207,40 +194,6 @@ impl AppRoutes {
app = app.route(&router.uri, router.method);
}

#[cfg(feature = "channels")]
if let Some(channels) = self.channels.as_ref() {
tracing::info!("[Middleware] +channels");
let channel_layer_app = tower::ServiceBuilder::new().layer(channels.layer.clone());
if ctx
.config
.server
.middlewares
.cors
.as_ref()
.is_some_and(super::middleware::MiddlewareLayer::is_enabled)
{
app = app.layer(
tower::ServiceBuilder::new()
.layer(
ctx.config
.server
.middlewares
.cors
.clone()
.unwrap_or_default()
.cors()?,
)
.layer(channel_layer_app),
);
} else {
app = app.layer(
tower::ServiceBuilder::new()
.layer(tower_http::cors::CorsLayer::permissive())
.layer(channel_layer_app),
);
}
}

let middlewares = self.middlewares::<H>(&ctx);
for mid in middlewares {
app = mid.apply(app)?;
Expand Down
47 changes: 0 additions & 47 deletions src/controller/channels.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
//!
//! ```rust
//! use async_trait::async_trait;
//! #[cfg(feature = "channels")]
//! use loco_rs::controller::channels::AppChannels;
//! use loco_rs::{
//! app::{AppContext, Hooks},
//! boot::{create_app, BootResult, StartMode},
Expand Down Expand Up @@ -49,13 +47,6 @@
//! create_app::<Self, Migrator>(mode, environment).await
//! }
//!
//! #[cfg(feature = "channels")]
//! /// Only when `channels` feature is enabled
//! fn register_channels(_ctx: &AppContext) -> AppChannels {
//! let channels = AppChannels::default();
//! //channels.register.ns("/", channels::application::on_connect);
//! channels
//! }
//! async fn connect_workers(_ctx: &AppContext, _queue: &Queue) -> Result<()> {
//! Ok(())
//! }
Expand Down Expand Up @@ -87,8 +78,6 @@ use crate::{errors::Error, Result};

mod app_routes;
mod backtrace;
#[cfg(feature = "channels")]
pub mod channels;
mod describe;
pub mod format;
#[cfg(feature = "with-db")]
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ pub mod testing;
#[cfg(feature = "testing")]
pub use axum_test::TestServer;
pub mod storage;
pub mod validation;
#[cfg(feature = "channels")]
pub use socketioxide;
#[cfg(feature = "testing")]
pub mod tests_cfg;
pub mod validation;
pub use validator;

/// Application results options list
Expand Down
8 changes: 0 additions & 8 deletions src/tests_cfg/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use async_trait::async_trait;
use sea_orm::DatabaseConnection;
pub use sea_orm_migration::prelude::*;

#[cfg(feature = "channels")]
use crate::controller::channels::AppChannels;
use crate::{
app::{AppContext, Hooks, Initializer},
bgworker::Queue,
Expand Down Expand Up @@ -120,10 +118,4 @@ impl Hooks for AppHook {
async fn seed(_db: &DatabaseConnection, _base: &Path) -> Result<()> {
Ok(())
}

#[cfg(feature = "channels")]
#[allow(clippy::unimplemented)]
fn register_channels(_ctx: &AppContext) -> AppChannels {
unimplemented!();
}
}

0 comments on commit eb78d7f

Please sign in to comment.