Skip to content

Commit

Permalink
change api routes and mount ui on root
Browse files Browse the repository at this point in the history
  • Loading branch information
OlofBlomqvist committed Oct 3, 2024
1 parent 0e2054c commit 868aa32
Show file tree
Hide file tree
Showing 27 changed files with 159 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "odd-box"
description = "dead simple reverse proxy server"
version = "0.1.7-preview"
version = "0.1.7-preview2"
edition = "2021"
authors = ["Olof Blomqvist <[email protected]>"]
repository = "https://github.com/OlofBlomqvist/odd-box"
Expand Down
61 changes: 61 additions & 0 deletions odd-box.toml.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#:schema https://raw.githubusercontent.com/OlofBlomqvist/odd-box/main/odd-box-schema-v2.json
version = "V2"
alpn = false
http_port = 8080
admin_api_port = 1234
ip = "0.0.0.0"
tls_port = 4343
auto_start = false
root_dir = "/tmp1"
log_level = "Error"
port_range_start = 4200
default_log_format = "standard"
lets_encrypt_account_email = ""
env_vars = [
{ key = "some_key", value = "some_val" },
{ key = "another_key", value = "another_val" },
]

[[remote_target]]
host_name = "caddy-remote.localtest.me"
backends = [
{ address="127.0.0.1", port=9999},
{ address="127.0.0.1", port=8888},
{ address="127.0.0.1", port=10000}
]

[[hosted_process]]
host_name = "caddy.localtest.me"
bin = "caddy"
args = [
"run",
"--config",
"./CaddyTest1",
"--adapter",
"caddyfile"
]
port = 9999

[[hosted_process]]
host_name = "caddy2.localtest.me"
bin = "caddy"
args = [
"run",
"--config",
"./CaddyTest2",
"--adapter",
"caddyfile"
]
port = 8888

[[hosted_process]]
host_name = "caddy3.localtest.me"
bin = "caddy"
args = [
"run",
"--config",
"./CaddyTest3",
"--adapter",
"caddyfile"
]
port = 10000
16 changes: 8 additions & 8 deletions src/api/controllers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ pub mod settings;
pub async fn routes(state:Arc<GlobalState>) -> Router {

let sites = Router::new()
.route("/sites", axum::routing::post(sites::update_handler)).with_state(state.clone())
.route("/sites", axum::routing::get(sites::list_handler)).with_state(state.clone())
.route("/sites", axum::routing::delete(sites::delete_handler)).with_state(state.clone())
.route("/sites/start", axum::routing::put(sites::start_handler)).with_state(state.clone())
.route("/sites/stop", axum::routing::put(sites::stop_handler)).with_state(state.clone())
.route("/sites/status", axum::routing::get(sites::status_handler)).with_state(state.clone())
.route("/api/sites", axum::routing::post(sites::update_handler)).with_state(state.clone())
.route("/api/sites", axum::routing::get(sites::list_handler)).with_state(state.clone())
.route("/api/sites", axum::routing::delete(sites::delete_handler)).with_state(state.clone())
.route("/api/sites/start", axum::routing::put(sites::start_handler)).with_state(state.clone())
.route("/api/sites/stop", axum::routing::put(sites::stop_handler)).with_state(state.clone())
.route("/api/sites/status", axum::routing::get(sites::status_handler)).with_state(state.clone())
;

let settings = Router::new()
.route("/settings", axum::routing::post(settings::set_settings_handler)).with_state(state.clone())
.route("/settings", axum::routing::get(settings::get_settings_handler)).with_state(state.clone());
.route("/api/settings", axum::routing::post(settings::set_settings_handler)).with_state(state.clone())
.route("/api/settings", axum::routing::get(settings::get_settings_handler)).with_state(state.clone());

sites.merge(settings)

Expand Down
4 changes: 2 additions & 2 deletions src/api/controllers/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub struct SaveGlobalConfig{
operation_id="settings",
get,
tag = "Settings",
path = "/settings",
path = "/api/settings",
responses(
(status = 200, description = "Successful Response", body = OddBoxConfigGlobalPart),
(status = 500, description = "When something goes wrong", body = String),
Expand Down Expand Up @@ -145,7 +145,7 @@ pub async fn get_settings_handler(
operation_id="save-settings",
post,
tag = "Settings",
path = "/settings",
path = "/api/settings",
request_body = SaveGlobalConfig,
responses(
(status = 200, description = "Successful Response"),
Expand Down
12 changes: 6 additions & 6 deletions src/api/controllers/sites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub struct StatusItem {
operation_id="list",
get,
tag = "Site management",
path = "/sites",
path = "/api/sites",
responses(
(status = 200, description = "Successful Response", body = ListResponse),
(status = 500, description = "When something goes wrong", body = String),
Expand All @@ -97,7 +97,7 @@ pub async fn list_handler(state: axum::extract::State<Arc<GlobalState>>) -> axum
operation_id="status",
get,
tag = "Site management",
path = "/sites/status",
path = "/api/sites/status",
responses(
(status = 200, description = "Successful Response", body = StatusResponse),
(status = 500, description = "When something goes wrong", body = String),
Expand Down Expand Up @@ -152,7 +152,7 @@ pub struct UpdateQuery {
params(
UpdateQuery
),
path = "/sites",
path = "/api/sites",
responses(
(status = 200, description = "Successful Response", body = ()),
(status = 500, description = "When something goes wrong", body = String),
Expand Down Expand Up @@ -214,7 +214,7 @@ pub struct DeleteQueryParams {
delete,
tag = "Site management",
params(DeleteQueryParams),
path = "/sites",
path = "/api/sites",
responses(
(status = 200, description = "Successful Response"),
(status = 500, description = "When something goes wrong", body = String),
Expand Down Expand Up @@ -303,7 +303,7 @@ pub struct StopQueryParams {
put,
tag = "Site management",
params(StopQueryParams),
path = "/sites/stop",
path = "/api/sites/stop",
responses(
(status = 200, description = "Successful Response"),
(status = 500, description = "When something goes wrong", body = String),
Expand Down Expand Up @@ -344,7 +344,7 @@ pub struct StartQueryParams {
put,
tag = "Site management",
params(StartQueryParams),
path = "/sites/start",
path = "/api/sites/start",
responses(
(status = 200, description = "Successful Response"),
(status = 500, description = "When something goes wrong", body = String),
Expand Down
2 changes: 1 addition & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub async fn run(globally_shared_state: Arc<crate::global_state::GlobalState>,po

// STATIC FILES FOR WEB-UI
.route("/", get(|| async { serve_static_file(axum::extract::Path("index.html".to_string())).await }))
.route("/webui/*file", get(serve_static_file));
.route("/*file", get(serve_static_file));

// in some cases one might want to allow CORS from a specific origin. this is not currently allowed to do from the config file
// so we use an environment variable to set this. might change in the future if it becomes a common use case
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 868aa32

Please sign in to comment.