fix: fix middlewares config

This commit is contained in:
master 2025-06-18 03:09:10 +08:00
parent 6726cafff4
commit cc06142050
4 changed files with 43 additions and 24 deletions

View File

@ -26,18 +26,18 @@ host = '{{ get_env(name="HOST", default="localhost") }}'
enable = true enable = true
# Generating a unique request ID and enhancing logging with additional information such as the start and completion of request processing, latency, status code, and other request details. # Generating a unique request ID and enhancing logging with additional information such as the start and completion of request processing, latency, status code, and other request details.
[server.middleware.request_id] [server.middlewares.request_id]
enable = true enable = true
[server.middleware.logger] [server.middlewares.logger]
enable = true enable = true
# when your code is panicked, the request still returns 500 status code. # when your code is panicked, the request still returns 500 status code.
[server.middleware.catch_panic] [server.middlewares.catch_panic]
enable = true enable = true
# Timeout for incoming requests middleware. requests that take more time from the configuration will cute and 408 status code will returned. # Timeout for incoming requests middleware. requests that take more time from the configuration will cute and 408 status code will returned.
[server.middleware.timeout_request] [server.middlewares.timeout_request]
enable = false enable = false
# Duration time in milliseconds. # Duration time in milliseconds.
timeout = 5000 timeout = 5000
@ -53,7 +53,10 @@ timeout = 5000
# - POST # - POST
# Set the value of the [`Access-Control-Max-Age`][mdn] header in seconds # Set the value of the [`Access-Control-Max-Age`][mdn] header in seconds
# max_age: 3600 # max_age: 3600
[server.middleware.cors] [server.middlewares.cors]
enable = true
[server.middlewares.compression]
enable = true enable = true
# Database Configuration # Database Configuration

View File

@ -6,6 +6,7 @@ use tracing::instrument;
use super::{builder::AppBuilder, context::AppContextTrait}; use super::{builder::AppBuilder, context::AppContextTrait};
use crate::{ use crate::{
app::Environment,
errors::{RecorderError, RecorderResult}, errors::{RecorderError, RecorderResult},
web::{ web::{
controller::{self, core::ControllerTrait}, controller::{self, core::ControllerTrait},
@ -64,8 +65,10 @@ impl App {
let middlewares = default_middleware_stack(context.clone()); let middlewares = default_middleware_stack(context.clone());
for mid in middlewares { for mid in middlewares {
router = mid.apply(router)?; if mid.is_enabled() {
tracing::info!(name = mid.name(), "+middleware"); router = mid.apply(router)?;
tracing::info!(name = mid.name(), "+middleware");
}
} }
let router = router let router = router
@ -86,13 +89,17 @@ impl App {
async { async {
{ {
let monitor = task.setup_monitor().await?; let monitor = task.setup_monitor().await?;
monitor if matches!(context.environment(), Environment::Development) {
.run_with_signal(async move { monitor.run().await?;
Self::shutdown_signal().await; } else {
tracing::info!("apalis shutting down..."); monitor
Ok(()) .run_with_signal(async move {
}) Self::shutdown_signal().await;
.await?; tracing::info!("apalis shutting down...");
Ok(())
})
.await?;
}
} }
Ok::<(), RecorderError>(()) Ok::<(), RecorderError>(())

View File

@ -1,6 +0,0 @@
---
source: apps/recorder/src/web/middleware/request_id.rs
assertion_line: 126
expression: id
---
"foo-barbaz"

View File

@ -1,9 +1,24 @@
import type { ComponentProps } from "react"; import { type ComponentProps } from "react";
export type ImgProps = Omit<ComponentProps<"img">, "alt"> & export type ImgProps = Omit<ComponentProps<"img">, "alt"> &
Required<Pick<ComponentProps<"img">, "alt">>; Required<Pick<ComponentProps<"img">, "alt">> & {
optimize?: boolean;
};
// biome-ignore lint/correctness/noUnusedVariables: <explanation>
const LEGACY_IMAGE_REGEX = /\.(jpg|jpeg|png|gif|svg)$/;
export const Img = (props: ImgProps) => { export const Img = (props: ImgProps) => {
// biome-ignore lint/nursery/noImgElement: <explanation> const src = props.src;
return <img {...props} alt={props.alt} />;
if (!src) {
// biome-ignore lint/nursery/noImgElement: <explanation>
return <img {...props} alt={props.alt} />;
}
return (
<picture {...props}>
<img {...props} alt={props.alt} />
</picture>
);
}; };