Skip to content

Commit

Permalink
Added Html Page in the root handler (#54)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Debajyoti14 authored May 19, 2024
1 parent d55ee36 commit a11d4d2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
26 changes: 25 additions & 1 deletion docs/local-setup/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
36 changes: 28 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -28,18 +31,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
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())))
.merge(routes::session_routes::routes(State(app_state.clone())))
.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())
Expand All @@ -48,6 +55,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
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#"
<!DOCTYPE html>
<html>
<head>
<title>FlexAuth</title>
</head>
<body>
<h1>Welcome to FlexAuth</h1>
<p>Your own flexible, blazingly fast 🦀, and secure in-house authentication system.</p>
<p>Here's the <a href="https://documenter.getpostman.com/view/18827552/2sA3JT4Jmd">API documentation</a>.</p>
</body>
</html>
"#;
Html(html_content)
}

0 comments on commit a11d4d2

Please sign in to comment.