feat(axum): add plain text

This commit is contained in:
xfy
2024-10-11 15:58:06 +08:00
parent 6b1e1ce1af
commit ac66b08931
3 changed files with 11 additions and 8 deletions

View File

@ -1,4 +1,6 @@
CARGO = cargo RUSTFLAGS := "-Z threads=8 -C target-cpu=native"
CARGO = RUSTFLAGS=$(RUSTFLAGS) cargo
RUSTC = rustc RUSTC = rustc
CROSS = cross CROSS = cross
@ -7,7 +9,7 @@ all: build
build: build:
$(CARGO) build $(CARGO) build
release: clean release:
$(CARGO) build --release $(CARGO) build --release
dev: dev:
@ -53,10 +55,4 @@ freebsd: clean-release
loongarch: clean-release loongarch: clean-release
$(CROSS) build --release --target loongarch64-unknown-linux-gnu $(CROSS) build --release --target loongarch64-unknown-linux-gnu
deps:
python -m venv venus \
&& source venus/bin/activate \
&& pip install -r scripts/requirements.txt \
&& python scripts/download-core.py
.PHONY: all .PHONY: all

View File

@ -20,6 +20,7 @@ use crate::{
}; };
pub mod json; pub mod json;
pub mod text;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub struct RouteResponse<T> pub struct RouteResponse<T>
@ -57,6 +58,7 @@ pub fn routes() -> Router {
let router = Router::new() let router = Router::new()
.route("/", get(hello).post(hello)) .route("/", get(hello).post(hello))
.route("/json", get(json::json).post(json::json)) .route("/json", get(json::json).post(json::json))
.route("/text", get(text::text).post(text::text))
.layer( .layer(
ServiceBuilder::new() ServiceBuilder::new()
.layer(middleware::from_fn(add_version)) .layer(middleware::from_fn(add_version))

View File

@ -0,0 +1,5 @@
use axum::response::IntoResponse;
pub async fn text() -> impl IntoResponse {
"xfy"
}