Skip to content

Commit 89da7d7

Browse files
committed
os: Use caddy instead of backend to serve frontend SPA
1 parent 96ad345 commit 89da7d7

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

backend/src/service.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,4 @@ app.get("/", async (req, res) => {
4747
return res.redirect(302, "/ps/node-red-v2/dashboard")
4848
})
4949

50-
const path_spa = "/home/pi/PlanktoScope/frontend/dist"
51-
app.use("/", express.static(path_spa))
52-
app.get("/{*splat}", (req, res) => {
53-
res.sendFile(path.join(path_spa, "index.html"))
54-
})
55-
5650
app.listen(4000)

frontend/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Start service for development:
1717
just dev
1818
```
1919

20+
Use `http://planktoscope-sponge-bob:3000/bookmarks` for preview.
21+
2022
Run the code auto-formatter on the project:
2123

2224
```sh

os/caddy/Caddyfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,22 @@
3131
file_server
3232
}
3333

34-
handle /* {
34+
handle /api/* {
35+
reverse_proxy localhost:4000
36+
}
37+
38+
# We want exact path / to go to backend where we have a redirect
39+
handle / {
3540
reverse_proxy localhost:4000
3641
}
3742

43+
# We want everyrthing else /* to frontend
44+
handle /* {
45+
root * /home/pi/PlanktoScope/frontend/dist
46+
try_files {path} /index.html
47+
file_server
48+
}
49+
3850
# https://github.com/ecotaxa/ecotaxa_back/issues/64
3951
handle_path /ecotaxa* {
4052
@cors_preflight {

os/caddy/justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ setup:
33
sudo cp Caddyfile /etc/caddy/
44
sudo systemctl reenable caddy
55
sudo systemctl restart caddy
6+
chmod o+x /home/pi
67

78
format:
89
caddy fmt --overwrite Caddyfile

0 commit comments

Comments
 (0)