Skip to content

Commit

Permalink
feat: remove error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dancixx committed Sep 3, 2024
1 parent 293fa55 commit f6e4f1d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 151 deletions.
11 changes: 3 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use leptos_icons::Icon;
use leptos_meta::*;
use leptos_router::*;

use crate::error_template::{AppError, ErrorTemplate};
use crate::{home, post};

#[component]
Expand Down Expand Up @@ -51,14 +50,10 @@ pub fn App() -> impl IntoView {
</div>
</header>
<main class="container flex flex-col gap-8 py-12 px-4 mx-auto mt-16 max-w-5xl md:px-0">
<Router fallback=|| {
let mut outside_errors = Errors::default();
outside_errors.insert_with_default_key(AppError::NotFound);
view! { <ErrorTemplate outside_errors /> }.into_view()
}>
<Router>
<Routes>
<Route path="" view=home::Component ssr=SsrMode::Async />
<Route path="/post/:slug" view=post::Component ssr=SsrMode::Async />
<Route path="/" view=home::Component ssr=SsrMode::Async />
<Route path="/post/:slug/" view=post::Component ssr=SsrMode::Async />
</Routes>
</Router>
</main>
Expand Down
72 changes: 0 additions & 72 deletions src/error_template.rs

This file was deleted.

60 changes: 0 additions & 60 deletions src/fileserv.rs

This file was deleted.

7 changes: 2 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

pub mod api;
pub mod app;
pub mod error_template;
#[cfg(feature = "ssr")]
pub mod fileserv;
#[cfg(feature = "ssr")]
pub mod redirect;
pub mod home;
pub mod post;
#[cfg(feature = "ssr")]
pub mod redirect;

#[cfg(feature = "hydrate")]
#[wasm_bindgen::prelude::wasm_bindgen]
Expand Down
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#[tokio::main]
async fn main() {
use axum::extract::State;
use axum::http::StatusCode;
use axum::response::Response;
use axum::{routing::get, Router};
use blog::api::{process_markdown, Post};
use blog::app::App;
use blog::fileserv::file_and_error_handler;
use blog::redirect::redirect_www;
use blog::ssr::AppState;
use chrono::{DateTime, Utc};
use blog::redirect::redirect_www;
use dotenvy::dotenv;
use leptos::*;
use leptos_axum::{generate_route_list, LeptosRoutes};
Expand Down Expand Up @@ -138,8 +138,12 @@ async fn main() {
App,
)
.route("/rss.xml", get(rss_handler))
.fallback(file_and_error_handler)
.layer(tower::ServiceBuilder::new().layer(TraceLayer::new_for_http()).layer(axum::middleware::from_fn(redirect_www)))
.fallback((|| (StatusCode::NOT_FOUND, "Not Found".to_string()))())
.layer(
tower::ServiceBuilder::new()
.layer(TraceLayer::new_for_http())
.layer(axum::middleware::from_fn(redirect_www)),
)
.with_state(app_state);

let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub fn Component() -> impl IntoView {
post.with(|post| {
let post = post.clone().unwrap_or_default();
view! {
// <Title text=post.title.to_string() />
// <Meta name="description" content=post.summary.to_string() />
<Title text=post.title.to_string() />
<Meta name="description" content=post.summary.to_string() />
// <Meta property="og:type" content="article" />
// <Meta property="og:title" content=post.title.to_string() />
// <Meta property="og:description" content=post.summary.to_string() />
Expand Down

0 comments on commit f6e4f1d

Please sign in to comment.