-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from nightly-labs/clean-api
Clean api
- Loading branch information
Showing
30 changed files
with
342 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
ENV=DEV # PROD or DEV | ||
ONLY_RELAY_SERVICE=True # TRUE - This will start only nightly relay service without cloud service | ||
NONCE=VERY_SECRET_NONCE | ||
JWT_SECRET=VERY_SECRET_SECRET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::state::ServerState; | ||
use axum::{extract::Request, http::StatusCode, middleware::Next, response::IntoResponse}; | ||
use std::sync::Arc; | ||
|
||
pub async fn db_cloud_middleware( | ||
req: Request, | ||
next: Next, | ||
) -> Result<impl IntoResponse, (StatusCode, String)> { | ||
// Extract the state from the request extensions | ||
let state = match req.extensions().get::<Arc<ServerState>>() { | ||
Some(state) => state, | ||
None => { | ||
return Err(( | ||
StatusCode::INTERNAL_SERVER_ERROR, | ||
"Corrupted server state".to_string(), | ||
)) | ||
} | ||
}; | ||
|
||
// Check if the database is connected | ||
if state.db.is_some() { | ||
// If the database is connected, pass the request to the next middleware or handler | ||
Ok(next.run(req).await) | ||
} else { | ||
// If the database is not connected, return an error response | ||
Err(( | ||
StatusCode::FORBIDDEN, | ||
"Cloud endpoints are disabled".to_string(), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod cloud_middleware; | ||
pub mod login_with_password; | ||
pub mod register_new_app; | ||
pub mod register_with_password; |
Oops, something went wrong.