Skip to content

Commit

Permalink
Re-add css and js faucet files
Browse files Browse the repository at this point in the history
Remove --testing from build package action
  • Loading branch information
Mirko-von-Leipzig committed Jan 24, 2025
1 parent 4a0d5a3 commit c7351db
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions bin/faucet/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum HandlerError {

#[error("invalid asset amount {requested} requested, valid options are {options:?}")]
InvalidAssetAmount { requested: u64, options: Vec<u64> },

#[error("not found")]
NotFound,
}

impl HandlerError {
Expand All @@ -38,6 +41,7 @@ impl HandlerError {
StatusCode::BAD_REQUEST
},
Self::ClientError(_) | Self::Internal(_) => StatusCode::INTERNAL_SERVER_ERROR,
Self::NotFound => StatusCode::NOT_FOUND,
}
}

Expand Down
11 changes: 7 additions & 4 deletions bin/faucet/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Context;
use axum::{
extract::State,
extract::{Path, State},
http::{Response, StatusCode},
response::IntoResponse,
Json,
Expand Down Expand Up @@ -116,10 +116,13 @@ pub async fn get_tokens(
.map_err(Into::into)
}

pub async fn get_index(state: State<FaucetState>) -> Result<impl IntoResponse, HandlerError> {
info!(target: COMPONENT, "Serving `index.html`");
pub async fn get_static_file(
State(state): State<FaucetState>,
Path(path): Path<String>,
) -> Result<impl IntoResponse, HandlerError> {
info!(target: COMPONENT, path, "Serving static file");

let static_file = state.static_files.get("index.html").expect("index.html should be bundled");
let static_file = state.static_files.get(path.as_str()).ok_or(HandlerError::NotFound)?;

Response::builder()
.status(StatusCode::OK)
Expand Down
4 changes: 2 additions & 2 deletions bin/faucet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tracing::info;

use crate::{
config::{FaucetConfig, DEFAULT_FAUCET_ACCOUNT_PATH},
handlers::{get_index, get_metadata, get_tokens},
handlers::{get_metadata, get_static_file, get_tokens},
};

// CONSTANTS
Expand Down Expand Up @@ -102,9 +102,9 @@ async fn main() -> anyhow::Result<()> {
info!(target: COMPONENT, %config, "Initializing server");

let app = Router::new()
.route("/", get(get_index))
.route("/get_metadata", get(get_metadata))
.route("/get_tokens", post(get_tokens))
.route("/*path", get(get_static_file))
.layer(
ServiceBuilder::new()
.layer(TraceLayer::new_for_http())
Expand Down

0 comments on commit c7351db

Please sign in to comment.