Add route for index, redirect to relative of current epoch time

This commit is contained in:
2023-07-22 18:15:15 -05:00
parent d963ce623d
commit 4e0e6f1d83
2 changed files with 8 additions and 2 deletions

View File

@@ -3,7 +3,7 @@ use std::net::SocketAddr;
use axum::{Router, routing::get};
use dotenvy::dotenv;
use config::Configuration;
use crate::routes::{relative_handler, implicit_handler, absolute_handler};
use crate::routes::{relative_handler, implicit_handler, absolute_handler, index_handler};
mod config;
mod raster;
@@ -29,6 +29,7 @@ async fn main() {
.init();
let app = Router::new()
.route("/", get(index_handler))
.route("/:path", get(implicit_handler))
.route("/rel/:path", get(relative_handler))
.route("/relative/:path", get(relative_handler))

View File

@@ -2,7 +2,7 @@ use axum::{http::StatusCode, response::IntoResponse};
use axum::body::{Bytes, Full};
use axum::extract::{Path};
use axum::http::{header};
use axum::response::Response;
use axum::response::{Redirect, Response};
use chrono::{DateTime, NaiveDateTime, Offset, Utc};
use crate::error::{get_error_response, TimeBannerError};
@@ -34,6 +34,11 @@ fn handle_rasterize(data: String, extension: &str) -> Result<(&str, Bytes), Time
}
}
pub async fn index_handler() -> impl IntoResponse {
let epoch_now = Utc::now().timestamp();
return Redirect::temporary(&*format!("/relative/{epoch_now}")).into_response();
}
pub async fn relative_handler(Path(path): Path<String>) -> impl IntoResponse {
let (raw_time, extension) = parse_path(path.as_str());
}