Skip to content

Commit bcd34a1

Browse files
committed
feat: Add port and request payload limit in .env
- Added `PORT` to specify the server listening port. - Added `OHKAMI_REQUEST_PAYLOAD_LIMIT` for security.
1 parent b2b1985 commit bcd34a1

File tree

6 files changed

+25
-185
lines changed

6 files changed

+25
-185
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
STORE_PATH="./.store"
22
CACHE_PATH="./.cache"
3+
PORT="3000"
4+
OHKAMI_REQUEST_PAYLOAD_LIMIT=4046

src/app.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub struct AppState {
5757
pub async fn app(
5858
lock: Lock,
5959
cache: Cache,
60+
address: &str,
6061
) {
6162
let router = Ohkami::new((
6263
Context::new(Arc::new(AppState {
@@ -81,5 +82,5 @@ pub async fn app(
8182
.expect("wtf");
8283

8384
let router = Ohkami::new(("/doc".GET(doc), "/".By(router)));
84-
router.howl("localhost:3000").await;
85+
router.howl(address).await;
8586
}

src/app/skin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub fn skin_router() -> Ohkami {
2727
}
2828

2929
#[derive(Debug, Clone, Deserialize, Schema, Hash, PartialEq, Eq, Serialize)]
30-
/// Params for expose Tee
3130
pub struct SkinQuery {
31+
/// Replace all whitespaces to `_`
3232
pub name: String,
3333
pub body: Option<u32>,
3434
pub feet: Option<u32>,

src/error.rs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ohkami::{IntoResponse, Response};
44
use reqwest::header::ToStrError;
55
use thiserror::Error;
66
use tokio::{io, task::JoinError};
7-
use tracing::error;
7+
use tracing::{error, instrument};
88

99
#[derive(Debug, Error)]
1010
pub enum Error {
@@ -33,39 +33,27 @@ pub enum Error {
3333
}
3434

3535
impl IntoResponse for Error {
36+
#[instrument]
3637
fn into_response(self) -> Response {
3738
match self {
38-
Error::Io(e) => {
39-
error!(error=%e,"I/O error");
40-
Response::InternalServerError().with_text("Skin not found")
41-
}
42-
Error::Tee(e) => {
43-
error!(error=%e,"Tee error");
44-
Response::InternalServerError().with_text("Fail to render uv")
45-
}
39+
Error::Io(_) => Response::InternalServerError().with_text("Skin not found"),
40+
Error::Tee(_) => Response::InternalServerError().with_text("Fail to render uv"),
4641
Error::QueryNameNotFound => {
47-
error!("Query expected name, but got none");
4842
Response::BadRequest().with_text("Query expected name, but got none")
4943
}
50-
Error::Reqwest(e) => {
51-
error!(error=%e,"Reqwest error");
52-
Response::InternalServerError()
53-
}
54-
Error::ToStrError(e) => {
55-
error!(error=%e,"Reqwest ToStr error");
56-
Response::InternalServerError()
57-
}
58-
Error::SaveFailed {
59-
path,
60-
name,
61-
error,
62-
} => todo!(),
44+
Error::Reqwest(_) => Response::InternalServerError(),
45+
Error::ToStrError(_) => Response::InternalServerError(),
6346
Error::DownloadFailed {
64-
name,
65-
error,
47+
name: _,
48+
error: _,
6649
} => todo!(),
67-
Error::TaskJoin(join_error) => todo!(),
68-
Error::Json(error) => todo!(),
50+
Error::TaskJoin(_join_error) => Response::InternalServerError(),
51+
Error::Json(_error) => Response::InternalServerError(),
52+
Error::SaveFailed {
53+
path: _,
54+
name: _,
55+
error: _,
56+
} => Response::InternalServerError(),
6957
}
7058
}
7159
}

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ async fn main() {
3636
dotenvy::dotenv().ok();
3737

3838
init_logger(Level::INFO);
39+
let address = format!(
40+
"0.0.0.0:{}",
41+
std::env::var("PORT").expect("PORT must be set")
42+
);
3943
let lock = Arc::new(
4044
LockStore::read(std::env::var("STORE_PATH").expect("STORE_PATH must be set"))
4145
.await
@@ -81,5 +85,5 @@ async fn main() {
8185
});
8286
}
8387

84-
app(lock, cache).await
88+
app(lock, cache, &address).await
8589
}

static/doc.html

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
 (0)