diff --git a/Cargo.toml b/Cargo.toml index 0d9cdd3..e4ea85d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,6 @@ pretty_assertions = "1.4.0" output-name = "ibis" bin-features = ["ssr"] lib-features = ["csr"] -site-addr = "127.0.0.1:8131" [lib] name = "ibis_lib" diff --git a/README.md b/README.md index 5db88b5..b0d02fd 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ trunk serve -w src/frontend/ Then open the site at [127.0.0.1:8080](http://127.0.0.1:8080/). Alternatively you can run `./scripts/watch.sh` to rebuild backend and frontend automatically on code changes (requires [cargo-watch](https://crates.io/crates/cargo-watch)). +By default the frontend runs on port 8080, which can be changed with env var `TRUNK_SERVE_PORT`. The backend port is 8081 and can be changed with `IBIS_BACKEND_PORT`. + ## License [AGPL](LICENSE) diff --git a/Trunk.toml b/Trunk.toml index 10005a7..0a3f0cd 100644 --- a/Trunk.toml +++ b/Trunk.toml @@ -1,6 +1,3 @@ [build] filehash = false target = "assets/index.html" - -[[proxy]] -backend = "http://127.0.0.1:8131" diff --git a/scripts/federation.sh b/scripts/federation.sh new file mode 100755 index 0000000..42899e4 --- /dev/null +++ b/scripts/federation.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +# launch a couple of local instances to test federation +# TODO: somehow instances use wrong port resulting in cors errors +(trap 'kill 0' SIGINT; + sh -c 'TRUNK_SERVE_PORT=8070 IBIS_BACKEND_PORT=8071 IBIS_DATABASE_URL="postgres://ibis:password@localhost:5432/ibis" ./scripts/watch.sh' & + sh -c 'TRUNK_SERVE_PORT=8080 IBIS_BACKEND_PORT=8081 ./scripts/watch.sh' & + sh -c 'TRUNK_SERVE_PORT=8090 IBIS_BACKEND_PORT=8091 ./scripts/watch.sh' +) \ No newline at end of file diff --git a/scripts/watch.sh b/scripts/watch.sh index 88bcbaf..5744766 100755 --- a/scripts/watch.sh +++ b/scripts/watch.sh @@ -1,11 +1,13 @@ #!/bin/sh set -e +IBIS_BACKEND_PORT="${IBIS_BACKEND_PORT:-8081}" + # run processes in parallel # https://stackoverflow.com/a/52033580 (trap 'kill 0' SIGINT; # start frontend - trunk serve -w src/frontend/ & + trunk serve -w src/frontend/ --proxy-backend http://127.0.0.1:$IBIS_BACKEND_PORT & # # start backend, with separate target folder to avoid rebuilds from arch change - CARGO_TARGET_DIR=target/backend cargo watch -c -x run + CARGO_TARGET_DIR=target/backend cargo watch -x run ) diff --git a/src/frontend/app.rs b/src/frontend/app.rs index ccf274f..85cf198 100644 --- a/src/frontend/app.rs +++ b/src/frontend/app.rs @@ -49,7 +49,8 @@ impl GlobalState { #[component] pub fn App() -> impl IntoView { - let backend_hostname = "127.0.0.1:8080".to_string(); + let port = option_env!("TRUNK_SERVE_PORT").unwrap_or("8080"); + let backend_hostname = format!("127.0.0.1:{port}"); provide_meta_context(); let backend_hostname = GlobalState { diff --git a/src/main.rs b/src/main.rs index 31b8ea8..8734618 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,8 +7,10 @@ pub async fn main() -> ibis_lib::backend::error::MyResult<()> { .filter_module("activitypub_federation", LevelFilter::Info) .filter_module("ibis", LevelFilter::Info) .init(); - let database_url = "postgres://ibis:password@localhost:5432/ibis"; - ibis_lib::backend::start("127.0.0.1:8131", database_url).await?; + let database_url = std::env::var("IBIS_DATABASE_URL") + .unwrap_or("postgres://ibis:password@localhost:5432/ibis".to_string()); + let port = std::env::var("IBIS_BACKEND_PORT").unwrap_or("8081".to_string()); + ibis_lib::backend::start(&format!("127.0.0.1:{port}"), &database_url).await?; Ok(()) }