Skip to content

Commit

Permalink
adjust for channels
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Oct 10, 2024
1 parent 9bda05b commit 9fb4ca6
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/controller/app_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//! configuring routes in an Axum application. It allows you to define route
//! prefixes, add routes, and configure middlewares for the application.
use std::fmt;

use axum::Router as AXRouter;
use lazy_static::lazy_static;
use regex::Regex;
use std::fmt;

#[cfg(feature = "channels")]
use super::channels::AppChannels;

use crate::{
app::{AppContext, Hooks},
controller::{middleware::MiddlewareLayer, routes::Routes},
Expand Down Expand Up @@ -209,10 +209,24 @@ impl AppRoutes {
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.is_enabled() {
if ctx
.config
.server
.middlewares
.cors
.map(|m| m.is_enabled())
.unwrap_or_default()
{
app = app.layer(
tower::ServiceBuilder::new()
.layer(ctx.config.server.middlewares.cors.cors()?)
.layer(
ctx.config
.server
.middlewares
.cors
.unwrap_or_default()
.cors()?,
)
.layer(channel_layer_app),
);
} else {
Expand All @@ -237,13 +251,13 @@ impl AppRoutes {
#[cfg(test)]
mod tests {

use super::*;
use crate::prelude::*;
use crate::tests_cfg;
use insta::assert_debug_snapshot;
use rstest::rstest;
use tower::ServiceExt;

use super::*;
use crate::{prelude::*, tests_cfg};

async fn action() -> Result<Response> {
format::json("loco")
}
Expand Down

0 comments on commit 9fb4ca6

Please sign in to comment.