Compare commits

..
1 Commits
Author SHA1 Message Date
joshuaandClaude Opus 5.5 c37349587c V1.32.1: the API can live under the site's own address
- Live updates connect to the path the API sits under (such as /api behind
  the site's own nginx), not only to an API on a host of its own: Socket.io
  reads a URL's path as a namespace, so the path now goes into its `path`
- README: how to serve the API under the site's address (.env values and
  the nginx location block)
- All packages at version 1.32.1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 23:41:43 +02:00
6 changed files with 41 additions and 8 deletions
+27
View File
@@ -106,6 +106,9 @@ including a character sheet or an encounter) and **Account**.
items) and by level in the class that gives them.
- **Armor holds Dexterity back** as in the rules: all of it counts toward AC
in light armor, at most +2 in medium, none in heavy.
- **The API can live under the site's own address**, such as `/api`
behind the same nginx, as well as on a host of its own (see "Serving the
API under the site's address").
- **Battles that keep to the fight.** While a battle is under way the scene
description shows only between rounds, cards' details start closed (the
spotlight, or on a phone the card on turn, has them), and the DM's setup,
@@ -234,6 +237,30 @@ old data model and pages that use anything new fail to load (for example
"Could not load this encounter"). Change your password from the account page
("Account" in the navigation).
### Serving the API under the site's address
The API can sit on its own host or under a path of the site, such as
`https://example.com/api`. For the second, set `VITE_API_URL=/api` in
`frontend/.env` before building (Vite bakes it in), set `CORS_ORIGIN` in
`backend/.env` to the site's address, and pass the path on in the site's
nginx config:
```nginx
location /api/ {
proxy_pass http://127.0.0.1:4000/; # the trailing slash strips /api
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 3600s;
}
```
The backend keeps seeing `/auth`, `/campaigns` and `/socket.io/` as before;
the live updates connect to `/api/socket.io`.
## Tests
```bash
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "backend",
"version": "1.32.0",
"version": "1.32.1",
"private": true,
"type": "commonjs",
"main": "src/index.js",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "frontend",
"private": true,
"version": "1.32.0",
"version": "1.32.1",
"type": "module",
"scripts": {
"dev": "vite",
+7 -1
View File
@@ -13,7 +13,13 @@ function getSocket(token: string): Socket {
// Starts on plain requests and moves up to a websocket when one gets
// through. Asking for the websocket first leaves no way back: behind a
// proxy that does not pass the upgrade, nothing live arrives at all.
sharedSocket = io(API_URL, { auth: { token } });
//
// Socket.io reads the path of a URL as a namespace, not as where the
// server lives. When the API sits under a path (such as /api behind the
// site's own nginx), that path has to go into `path` instead.
const url = new URL(API_URL, window.location.origin);
const base = url.pathname.replace(/\/$/, '');
sharedSocket = io(url.origin, { path: `${base}/socket.io`, auth: { token } });
}
return sharedSocket;
}
+4 -4
View File
@@ -1,19 +1,19 @@
{
"name": "dnd-campaign-manager",
"version": "1.32.0",
"version": "1.32.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "dnd-campaign-manager",
"version": "1.32.0",
"version": "1.32.1",
"workspaces": [
"backend",
"frontend"
]
},
"backend": {
"version": "1.32.0",
"version": "1.32.1",
"dependencies": {
"@prisma/adapter-pg": "^7.10.0",
"@prisma/client": "^7.10.0",
@@ -33,7 +33,7 @@
}
},
"frontend": {
"version": "1.32.0",
"version": "1.32.1",
"dependencies": {
"@tanstack/react-query": "^5.103.2",
"axios": "^1.20.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dnd-campaign-manager",
"version": "1.32.0",
"version": "1.32.1",
"private": true,
"description": "D&D 5e campaign manager — monorepo root",
"workspaces": [