-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 #1060 from TabbyML/extract-public-mod
refactor(webserver): extract tabby_webserver::public to centralize it…
- Loading branch information
Showing
7 changed files
with
101 additions
and
66 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
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,56 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::{ | ||
extract::State, | ||
http::Request, | ||
middleware::{from_fn_with_state, Next}, | ||
routing, Extension, Router, | ||
}; | ||
use hyper::Body; | ||
use juniper_axum::{graphiql, graphql, playground}; | ||
use tabby_common::api::{code::CodeSearch, event::RawEventLogger}; | ||
|
||
use crate::{ | ||
hub, repositories, | ||
schema::{create_schema, Schema, ServiceLocator}, | ||
service::create_service_locator, | ||
ui, | ||
}; | ||
|
||
pub async fn attach_webserver( | ||
api: Router, | ||
ui: Router, | ||
logger: Arc<dyn RawEventLogger>, | ||
code: Arc<dyn CodeSearch>, | ||
) -> (Router, Router) { | ||
let ctx = create_service_locator(logger, code).await; | ||
let schema = Arc::new(create_schema()); | ||
|
||
let api = api | ||
.layer(from_fn_with_state(ctx.clone(), distributed_tabby_layer)) | ||
.route( | ||
"/graphql", | ||
routing::post(graphql::<Arc<Schema>, Arc<dyn ServiceLocator>>).with_state(ctx.clone()), | ||
) | ||
.route("/graphql", routing::get(playground("/graphql", None))) | ||
.layer(Extension(schema)) | ||
.route( | ||
"/hub", | ||
routing::get(hub::ws_handler).with_state(ctx.clone()), | ||
) | ||
.nest("/repositories", repositories::routes(ctx.clone())); | ||
|
||
let ui = ui | ||
.route("/graphiql", routing::get(graphiql("/graphql", None))) | ||
.fallback(ui::handler); | ||
|
||
(api, ui) | ||
} | ||
|
||
async fn distributed_tabby_layer( | ||
State(ws): State<Arc<dyn ServiceLocator>>, | ||
request: Request<Body>, | ||
next: Next<Body>, | ||
) -> axum::response::Response { | ||
ws.worker().dispatch_request(request, next).await | ||
} |
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