1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-25 03:01:09 +00:00

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