Skip to content

Commit 6f62cb8

Browse files
committed
flake: add run-stack helper
1 parent 88c3245 commit 6f62cb8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

flake.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,45 @@
8686
};
8787

8888
packages = {
89+
run-stack = pkgs.writeShellApplication {
90+
name = "run-stack";
91+
runtimeInputs = [
92+
pkgs.tinyproxy
93+
pkgs.simple-http-server
94+
];
95+
text =
96+
let
97+
proxyConfig = pkgs.writeTextFile {
98+
name = "proxy.conf";
99+
text = ''
100+
ReversePath "/" "http://0.0.0.0:8001/"
101+
ReversePath "/api/" "http://0.0.0.0:8002/api/"
102+
ReverseOnly Yes
103+
Port 8000
104+
ReverseBaseURL "http://0.0.0.0:8000/"
105+
'';
106+
};
107+
in
108+
''
109+
simple-http-server --index --port 8001 frontend &
110+
PID_FRONTEND=$!
111+
cargo run -- --listen-address 0.0.0.0:8002 &
112+
PID_BACKEND=$!
113+
tinyproxy -d -c ${proxyConfig} &
114+
PID_PROXY=$!
115+
116+
cleanup() {
117+
kill $PID_FRONTEND $PID_BACKEND $PID_PROXY
118+
wait $PID_FRONTEND $PID_BACKEND $PID_PROXY
119+
exit 0
120+
}
121+
122+
trap cleanup SIGINT
123+
124+
wait $PID_FRONTEND $PID_BACKEND $PID_PROXY
125+
'';
126+
};
127+
89128
server-deps = craneLib.buildDepsOnly commonAttrs;
90129

91130
server-docs = craneLib.cargoDoc (

0 commit comments

Comments
 (0)