mod: add test gemini endpoint
This commit is contained in:
2 files changed
+49
-7
No files matched your search
@@ -1,5 +1,22 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub enum ServeAppConfig {
|
||||||
|
Http,
|
||||||
|
Gemini,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::str::FromStr for ServeAppConfig {
|
||||||
|
type Err = &'static str;
|
||||||
|
|
||||||
|
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||||
|
match value {
|
||||||
|
"http" => Ok(Self::Http),
|
||||||
|
"gemini" => Ok(Self::Gemini),
|
||||||
|
_ => Err("expected \"http\" or \"gemini\""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn config() -> Configuration {
|
pub fn config() -> Configuration {
|
||||||
Configuration {
|
Configuration {
|
||||||
env: dotenvy::dotenv(),
|
env: dotenvy::dotenv(),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use axum::Router;
|
use axum::Router;
|
||||||
|
use gemi::{EndpointExt, GeminiConfig, GeminiResponse, GeminiRouter, GeminiServer};
|
||||||
use cache::ClientLike;
|
use cache::ClientLike;
|
||||||
use config::config;
|
use config::config;
|
||||||
use sqlx::postgres::PgPoolOptions;
|
use sqlx::postgres::PgPoolOptions;
|
||||||
@@ -115,12 +116,20 @@ async fn main() {
|
|||||||
let app_state = Arc::new(Mutex::new(state::AppInternalState::new(pool, redis_pool)));
|
let app_state = Arc::new(Mutex::new(state::AppInternalState::new(pool, redis_pool)));
|
||||||
|
|
||||||
// build our application with some routes
|
// build our application with some routes
|
||||||
|
let app_env = std::env::var("SERVE_APP")
|
||||||
|
.unwrap_or_else(|_| "http".to_string())
|
||||||
|
.parse::<config::ServeAppConfig>()
|
||||||
|
.expect("Invalid SERVE_APP value");
|
||||||
|
|
||||||
|
match app_env {
|
||||||
|
config::ServeAppConfig::Http => {
|
||||||
|
let state = app_state.clone();
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.merge(routes::root::RootRoute::routes())
|
.merge(routes::root::RootRoute::routes())
|
||||||
.merge(routes::posts::PostsRoute::routes(&app_state))
|
.merge(routes::posts::PostsRoute::routes(&state))
|
||||||
.merge(routes::comments::CommentsRoute::routes(&app_state))
|
.merge(routes::comments::CommentsRoute::routes(&state))
|
||||||
.merge(routes::authors::AuthorsRoute::routes(&app_state))
|
.merge(routes::authors::AuthorsRoute::routes(&state))
|
||||||
.merge(routes::projects::ProjectsRoute::routes(&app_state))
|
.merge(routes::projects::ProjectsRoute::routes(&state))
|
||||||
.layer(CorsLayer::permissive())
|
.layer(CorsLayer::permissive())
|
||||||
.layer(
|
.layer(
|
||||||
TraceLayer::new_for_http()
|
TraceLayer::new_for_http()
|
||||||
@@ -128,9 +137,7 @@ async fn main() {
|
|||||||
.on_response(trace::DefaultOnResponse::new().level(tracing::Level::INFO)),
|
.on_response(trace::DefaultOnResponse::new().level(tracing::Level::INFO)),
|
||||||
)
|
)
|
||||||
.fallback(routes::root::RootRoute::not_found);
|
.fallback(routes::root::RootRoute::not_found);
|
||||||
//.layer(GovernorLayer {
|
|
||||||
// config: governor_conf,
|
|
||||||
//});
|
|
||||||
|
|
||||||
// run it with hyper
|
// run it with hyper
|
||||||
let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||||
@@ -140,6 +147,24 @@ async fn main() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
config::ServeAppConfig::Gemini => {
|
||||||
|
let gemini_state = app_state.clone();
|
||||||
|
let mut router = GeminiRouter::default();
|
||||||
|
router.add_route("/", hello).unwrap();
|
||||||
|
// router.nest(prefix, endpoint)
|
||||||
|
let config = GeminiConfig::new("0.0.0.0:1965");
|
||||||
|
let app = router.with_state(gemini_state);
|
||||||
|
let server = GeminiServer::new(app, "cert.der", "key.der", config).unwrap();
|
||||||
|
server.serve().await.unwrap();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn hello() -> impl Into<GeminiResponse> {
|
||||||
|
"Hello, Gemini!"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn shutdown_signal() {
|
async fn shutdown_signal() {
|
||||||
let ctrl_c = async {
|
let ctrl_c = async {
|
||||||
|
|||||||
Reference in new issue
Block a user