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>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "1.32.0",
|
||||
"version": "1.32.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user