add scripts for watch/federate

This commit is contained in:
Felix Ableitner 2024-01-30 12:32:02 +01:00
parent 334a923d79
commit 98a9ca2439
7 changed files with 22 additions and 9 deletions

View File

@ -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"

View File

@ -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)

View File

@ -1,6 +1,3 @@
[build]
filehash = false
target = "assets/index.html"
[[proxy]]
backend = "http://127.0.0.1:8131"

10
scripts/federation.sh Executable file
View File

@ -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'
)

View File

@ -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
)

View File

@ -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 {

View File

@ -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(())
}