From a11d4d2e0f2aebca4f9681e30725a65d04b79c73 Mon Sep 17 00:00:00 2001 From: Debajyoti Saha <91759192+Debajyoti14@users.noreply.github.com> Date: Sun, 19 May 2024 13:46:59 +0530 Subject: [PATCH] Added Html Page in the root handler (#54) * Password validation Changed * Add Special Character support for password * Added Docs for Local Setup with folder structure * Updated Docs * Removed the api-docs sec * Added HTML Page on the root_handler and fixed docs --- docs/local-setup/readme.md | 26 +++++++++++++++++++++++++- src/main.rs | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/docs/local-setup/readme.md b/docs/local-setup/readme.md index e6a0077..0ff3ec5 100644 --- a/docs/local-setup/readme.md +++ b/docs/local-setup/readme.md @@ -37,12 +37,13 @@ openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:204 ### Step 3: Spinning up Docker Containers -Not it's time to run the docker container by running this following command (Make sure you have Docker installed) +Now it's time to run the docker container by running this following command (Make sure you have Docker installed) ``` docker compose up ``` +This command will start the container and watch the /src folder for any changes. If there are any modifications to the content inside /src, the container will automatically hot reload to reflect those changes. Note:- If there's any changes outside of the `/src` directory like- `cargo.toml` file, Make sure to stop the container and run the docker container with `--build` flag @@ -51,4 +52,27 @@ docker compose up --build ``` +### Step 4: Connecting to MongoDB Compass + +After running the Docker containers, you can connect to the MongoDB database using MongoDB Compass. Follow these steps: + +1. **Open MongoDB Compass**: Launch MongoDB Compass on your system. + +2. **Connect to a MongoDB Deployment**: + - Click on the "New Connection" button to create a new connection. + - In the "Connection String" field, paste the following URI: + ```plaintext + mongodb://admin:admin@localhost:27017/?directConnection=true&retryWrites=true&w=majority + ``` + - Replace the default URI with the one appropriate for your setup if necessary. This URI includes the credentials (`admin:admin`) and the default MongoDB port (`27017`). + +3. **Connect to the Database**: + - Click on the "Connect" button to establish a connection to the MongoDB deployment. + - If the connection is successful, you will be able to browse and interact with the databases and collections in your MongoDB instance using MongoDB Compass. + +4. **Explore Data**: You can now explore your MongoDB databases, collections, and documents, run queries, and perform other operations using MongoDB Compass. + +That's it! You are now connected to your MongoDB database using MongoDB Compass. + + Congrats, Your Local Setup is done successfully. diff --git a/src/main.rs b/src/main.rs index 50bbc29..debcafe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,7 @@ -use axum::{extract::State, middleware, routing::get, Router}; +use axum::extract::State; +use axum::response::Html; +use axum::routing::get; +use axum::{middleware, Router}; use dotenv::dotenv; use middlewares::res_log::main_response_mapper; use middlewares::with_api_key::with_api_key; @@ -28,10 +31,8 @@ async fn main() -> Result<(), Box> { config::init::init_users(mongo_client.clone()).await; let app_state = AppState { mongo_client }; - // run the server - let routes = Router::new() - .route("/", get(root_handler)) - .merge(routes::health_check_routes::routes()) + // Define routes where middleware is applied + let protected_routes = Router::new() .merge(routes::auth_routes::routes(State(app_state.clone()))) .merge(routes::user_routes::routes(State(app_state.clone()))) .merge(routes::password_routes::routes(State(app_state.clone()))) @@ -39,7 +40,13 @@ async fn main() -> Result<(), Box> { .layer(middleware::map_response(main_response_mapper)) .layer(middleware::from_fn(with_api_key)); - let app = Router::new().nest("/api", routes); + // Define routes where middleware is not applied + let public_routes = Router::new().route("/", get(root_handler)); + + // Combine public and protected routes + let app = Router::new() + .nest("/api", protected_routes) + .nest("/", public_routes); let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap(); axum::serve::serve(listener, app.into_make_service()) @@ -48,6 +55,19 @@ async fn main() -> Result<(), Box> { Ok(()) } -async fn root_handler() -> &'static str { - "Hello, welcome to in-house auth service!" +async fn root_handler() -> Html<&'static str> { + let html_content = r#" + + + + FlexAuth + + +

Welcome to FlexAuth

+

Your own flexible, blazingly fast 🦀, and secure in-house authentication system.

+

Here's the API documentation.

+ + + "#; + Html(html_content) }