-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#85) Add copy of kkomelin/sui-explorer single-file-build branch
- Loading branch information
1 parent
fe52436
commit ef7e17e
Showing
790 changed files
with
51,044 additions
and
0 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
133 changes: 133 additions & 0 deletions
133
rust/suibase/crates/suibase-daemon/src/workers/webserver.rs
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,133 @@ | ||
// Run a webserver to serve all files in a specified directory. | ||
// | ||
// The tokio task is auto-restart in case of panic. | ||
|
||
use crate::shared_types::Globals; | ||
|
||
use anyhow::Result; | ||
use axum::async_trait; | ||
|
||
use common::basic_types::{AdminControllerTx, AutoThread, Runnable}; | ||
|
||
use tokio_graceful_shutdown::{FutureExt, SubsystemHandle}; | ||
|
||
#[derive(Clone)] | ||
pub struct WebserverParams { | ||
globals: Globals, | ||
admctrl_tx: AdminControllerTx, | ||
website_name: String, | ||
} | ||
|
||
impl WebserverParams { | ||
pub fn new(globals: Globals, admctrl_tx: AdminControllerTx, website_name: &str) -> Self { | ||
Self { | ||
globals, | ||
admctrl_tx, | ||
website_name: website_name.to_owned(), | ||
} | ||
} | ||
} | ||
|
||
pub struct WebserverWorker { | ||
auto_thread: AutoThread<WebserverTask, WebserverParams>, | ||
} | ||
|
||
impl WebserverWorker { | ||
pub fn new(params: WebserverParams) -> Self { | ||
let name = format!("Webserver({})", params.website_name); | ||
Self { | ||
auto_thread: AutoThread::new(name, params), | ||
} | ||
} | ||
|
||
pub async fn run(self, subsys: SubsystemHandle) -> Result<()> { | ||
self.auto_thread.run(subsys).await | ||
} | ||
} | ||
|
||
struct WebserverTask { | ||
task_name: String, | ||
params: WebserverParams, | ||
websites_root: String, | ||
} | ||
|
||
#[async_trait] | ||
impl Runnable<WebserverParams> for WebserverTask { | ||
fn new(task_name: String, params: WebserverParams) -> Self { | ||
Self { | ||
task_name, | ||
params, | ||
websites_root: "".to_string(), | ||
} | ||
} | ||
|
||
async fn run(mut self, subsys: SubsystemHandle) -> Result<()> { | ||
// The websites (static files) are stored under "~/suibase/typescript". | ||
// websites_root has the ~ resolved (e.g. "/home/user_name/suibase/typescript") | ||
self.websites_root = format!("{}/typescript", { | ||
let workdirs_guard = self.params.globals.workdirs.read().await; | ||
let workdirs = &*workdirs_guard; | ||
workdirs.suibase_home().to_string() | ||
}); | ||
|
||
let output = format!("started {}", self.task_name); | ||
log::info!("{}", output); | ||
|
||
match self.event_loop(&subsys).cancel_on_shutdown(&subsys).await { | ||
Ok(_) => { | ||
log::info!("normal task exit (2)"); | ||
Ok(()) | ||
} | ||
Err(_cancelled_by_shutdown) => { | ||
log::info!("{} normal task exit (1)", self.task_name); | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl WebserverTask { | ||
async fn event_loop(&mut self, _subsys: &SubsystemHandle) -> Result<()> { | ||
// Serve files located under self.websites_root ("~/suibase/typescript" with ~ resolved). | ||
let static_files_path = if self.params.website_name == "sui-explorer" { | ||
// Serve the explorer app | ||
format!("{}/sui-explorer/apps/explorer/build", self.websites_root) | ||
} else { | ||
// Serve whatever is at "~/suibase/typescript/website_name" | ||
format!("{}/{}", self.websites_root, self.params.website_name) | ||
}; | ||
|
||
// Use tower to handle the serving of the static files + index.html | ||
let tower_srvc = tower_http::services::ServeDir::new(static_files_path) | ||
.append_index_html_on_directories(true); | ||
|
||
// Setup the router to always use the tower service. | ||
// | ||
// There is no caching, the files are purposely read and served on each request. | ||
// | ||
// Why? The Suibase webserver favor KISS over performance (modifying the files | ||
// update the "website" on next request/refresh). | ||
let app = axum::Router::new().fallback( | ||
axum::routing::get_service(tower_srvc).handle_error(|error| async move { | ||
( | ||
axum::http::StatusCode::INTERNAL_SERVER_ERROR, | ||
format!("Unhandled internal error: {}", error), | ||
) | ||
}), | ||
); | ||
|
||
// Define the address to serve on | ||
// | ||
// TODO Get this from the yaml configuration. | ||
let addr = std::net::SocketAddr::from(([0, 0, 0, 0], 44380)); | ||
log::info!("{} listening on {}", self.task_name, addr); | ||
|
||
// Run the server | ||
axum::Server::bind(&addr) | ||
.serve(app.into_make_service()) | ||
.await | ||
.map_err(|e| anyhow::anyhow!("Server error: {}", e))?; | ||
|
||
Ok(()) | ||
} | ||
} |
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,76 @@ | ||
# IDE | ||
**/.history/ | ||
**/.vscode/ | ||
**/.idea/ | ||
|
||
# OSX | ||
.DS_Store | ||
|
||
# Rust build directory | ||
**/target | ||
.pre-commit* | ||
|
||
# Move build directory | ||
build | ||
!crates/sui-single-node-benchmark/tests/data/package_publish_from_bytecode/package_a/build | ||
!crates/sui-single-node-benchmark/tests/data/package_publish_from_bytecode/package_b/build | ||
storage | ||
!consensus/core/src/storage | ||
!crates/sui-types/src/storage | ||
!narwhal/storage | ||
|
||
# Move-related files | ||
Move.lock | ||
!crates/sui-framework/packages/move-stdlib/Move.lock | ||
!crates/sui-framework/packages/sui-framework/Move.lock | ||
!crates/sui-framework/packages/sui-system/Move.lock | ||
!crates/sui-framework/packages/deepbook/Move.lock | ||
.trace | ||
.coverage_map.mvcov | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Emacs | ||
\#*\# | ||
.\#* | ||
|
||
# Python | ||
.pyc | ||
|
||
# Node.js | ||
node_modules | ||
.tsbuildinfo | ||
*.tsbuildinfo | ||
.turbo | ||
|
||
# App build directories | ||
dist/ | ||
storybook-static/ | ||
web-ext-artifacts/ | ||
.next/ | ||
next-env.d.ts | ||
|
||
# App test artifacts | ||
coverage/ | ||
test-results/ | ||
playwright-report/ | ||
playwright/.cache/ | ||
|
||
# logs | ||
wallet.log.* | ||
sui.log.* | ||
.vercel | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# misc | ||
*.key | ||
.env | ||
checkpoints_dir/* | ||
light_client.yaml | ||
docs/content/references/sui-api/sui-graphql/* | ||
docs/content/references/framework/** | ||
|
||
lcov.info |
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 @@ | ||
pnpm build |
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 @@ | ||
According to the Apache-2.0 license, a fork should clearly state the list of changes made, | ||
so here is the full list of changes after forking the project from https://github.com/MystenLabs/sui-explorer: | ||
|
||
https://github.com/kkomelin/sui-explorer/compare/before-fork...kkomelin:sui-explorer:main |
Oops, something went wrong.