Skip to content

Commit

Permalink
Update example depencencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaj committed Jun 9, 2024
1 parent e8e358d commit 0d7cd12
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ructe = { path = "../..", features = ["sass", "mime03"] }
[dependencies]
actix-web = "4.2.1"
mime = "0.3"
env_logger = "0.10.0"
env_logger = "0.11.3"
6 changes: 3 additions & 3 deletions examples/axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ build = "src/build.rs"
ructe = { path = "../..", features = ["sass", "mime03"] }

[dependencies]
axum = { version = "0.6.2", features = ["headers"] }
env_logger = "0.10.0"
headers = "0.3.8"
axum = "0.7.5"
env_logger = "0.11.3"
log = "0.4.21"
mime = "0.3"
tokio = { version = "1.21.2", default-features = false, features = ["rt-multi-thread", "macros"] }
34 changes: 18 additions & 16 deletions examples/axum/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use axum::{
extract::Path,
http::StatusCode,
http::{header, StatusCode},
response::{IntoResponse, Response},
routing::get,
Router, Server, TypedHeader,
Router,
};
use headers::{ContentType, Expires};

use std::{
io::{self, Write},
time::{Duration, SystemTime},
};
use std::io::{self, Write};

use templates::statics::StaticFile;

Expand Down Expand Up @@ -38,15 +34,18 @@ async fn home_page() -> impl IntoResponse {
/// Handler for static files.
/// Create a response from the file data with a correct content type
/// and a far expires header (or a 404 if the file does not exist).
async fn static_files(Path(filename): Path<String>) -> impl IntoResponse {
/// A duration to add to current time for a far expires header.
static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60);
async fn static_files(Path(filename): Path<String>) -> Response {
match StaticFile::get(&filename) {
Some(data) => {
let far_expires = SystemTime::now() + FAR;
(
TypedHeader(ContentType::from(data.mime.clone())),
TypedHeader(Expires::from(far_expires)),
[
(header::CONTENT_TYPE, data.mime.as_ref()),
(
header::CACHE_CONTROL,
// max age is 180 days (given in seconds)
"public, max_age=15552000, immutable",
),
],
data.content,
)
.into_response()
Expand Down Expand Up @@ -79,7 +78,7 @@ async fn make_error() -> Result<impl IntoResponse, ExampleAppError> {
/// The error type that can be returned from resource handlers.
///
/// This needs to be convertible from any error types used with `?` in
/// handlers, and implement the actix ResponseError type.
/// handlers, and implement the axum [IntoResponse] trait.
#[derive(Debug)]
enum ExampleAppError {
ParseInt(std::num::ParseIntError),
Expand Down Expand Up @@ -139,8 +138,11 @@ fn error_response(
#[tokio::main]
async fn main() {
env_logger::init();
Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app().into_make_service())

let listener =
tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
log::info!("Listening on {}.", listener.local_addr().unwrap());
axum::serve(listener, app().into_make_service())
.await
.unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion examples/warp03/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ ructe = { path = "../..", features = ["warp03", "sass"] }
[dependencies]
warp = "0.3.0"
mime = "0.3.0"
env_logger = "0.10.0"
env_logger = "0.11.3"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
log = "0.4.14"

0 comments on commit 0d7cd12

Please sign in to comment.