File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import * as consola from 'consola'
66import setupApp from './src/server/extension.setup'
77import { loadingBarHijackFilter } from './src/composables/useLoadingBarHijackFilter'
88
9- const SESAME_APP_API_URL = process . env . SESAME_APP_API_URL || 'http://localhost:4002 '
9+ const SESAME_APP_API_URL = process . env . SESAME_APP_API_URL || 'http://127.0.0.1:4000 '
1010/** URL API exposée au navigateur (WebSocket). Ex. http://mactacx:4002 si l'API est joignable sur ce host. */
1111const SESAME_APP_PUBLIC_API_URL = process . env . SESAME_APP_PUBLIC_API_URL || ''
1212const SESAME_ALLOWED_HOSTS = process . env . SESAME_ALLOWED_HOSTS ? process . env . SESAME_ALLOWED_HOSTS . split ( ',' ) : [ ]
@@ -263,9 +263,6 @@ export default defineNuxtConfig({
263263 } ,
264264 } ,
265265 routeRules : {
266- '/socket.io' : {
267- proxy : `${ SOCKET_IO_PROXY_TARGET } /socket.io` ,
268- } ,
269266 '/api/**' : {
270267 proxy : `${ SESAME_APP_API_URL } /**` ,
271268 } ,
Original file line number Diff line number Diff line change 11/**
22 * Origine Socket.IO côté navigateur.
3- * En dev/prod, le client se connecte à la même origine que le front ; Nitro/Vite proxifient `/socket.io` vers l'API.
3+ * Par défaut : même origine que le front (Nitro/Vite proxifient `/socket.io` vers l'API).
4+ * Si `SESAME_APP_PUBLIC_API_URL` est défini : connexion directe à l'API (requis quand le
5+ * reverse-proxy route `/socket.io` vers le port 4000 ou que le proxy Nitro n'est pas joignable).
46 */
57export function resolveSocketApiOrigin ( ) : string {
6- if ( import . meta. client ) {
7- return window . location . origin
8- }
9-
10- const appConfig = useAppConfig ( )
118 const runtimeConfig = useRuntimeConfig ( )
129 const configuredPublic = `${ runtimeConfig . public . socketApiUrl || '' } ` . trim ( )
1310
1411 if ( configuredPublic ) {
1512 return new URL ( configuredPublic ) . origin
1613 }
1714
15+ if ( import . meta. client ) {
16+ return window . location . origin
17+ }
18+
19+ const appConfig = useAppConfig ( )
1820 return `${ appConfig . baseUrl || '' } ` . replace ( / \/ $ / , '' )
1921}
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import { IdentityState } from '~/constants/enums'
2424import { useIdentityStateStore } from ' ~/stores/identityState'
2525import { loadingBarDefaults } from ' ~/composables/useLoadingBarHijackFilter'
2626import { attachSocketIoDebug } from ' ~/composables/useSocketIoDebug'
27+ import { resolveSocketApiOrigin } from ' ~/composables/useSocketApiOrigin'
2728import { io , type Socket } from ' socket.io-client'
2829
2930export default defineNuxtComponent ({
@@ -158,7 +159,7 @@ export default defineNuxtComponent({
158159
159160 this .disconnectBackendsSocket ()
160161
161- this .socket = io (' /core/backends' , {
162+ this .socket = io (` ${ resolveSocketApiOrigin ()} /core/backends` , {
162163 path: ' /socket.io' ,
163164 query: { id: String (id ), key: String (key ) },
164165 transports: [' polling' ],
Original file line number Diff line number Diff line change 220220import type { LocationQueryValue } from ' vue-router'
221221import { reactive , ref } from ' vue'
222222import { attachSocketIoDebug } from ' ~/composables/useSocketIoDebug'
223+ import { resolveSocketApiOrigin } from ' ~/composables/useSocketApiOrigin'
223224import { io , type Socket } from ' socket.io-client'
224225import { NewTargetId } from ' ~/constants/variables'
225226
@@ -596,7 +597,7 @@ export default defineNuxtComponent({
596597 this .logsFollowTail = true
597598 this .logsLoading = true
598599
599- this .logsSocket = io (' /core/cron' , {
600+ this .logsSocket = io (` ${ resolveSocketApiOrigin ()} /core/cron` , {
600601 path: ' /socket.io' ,
601602 query: { id: String (id ), key: String (key ) },
602603 transports: [' polling' ],
Original file line number Diff line number Diff line change 1+ import { defineEventHandler , proxyRequest } from 'h3'
2+
3+ const DEFAULT_API_URL = 'http://127.0.0.1:4000'
4+
5+ function resolveApiBaseUrl ( ) : string {
6+ return ( process . env . SESAME_APP_API_URL || DEFAULT_API_URL ) . replace ( / \/ $ / , '' )
7+ }
8+
9+ export default defineEventHandler ( async ( event ) => {
10+ const url = event . node . req . url || ''
11+ if ( ! url . startsWith ( '/socket.io' ) ) {
12+ return
13+ }
14+
15+ return proxyRequest ( event , `${ resolveApiBaseUrl ( ) } ${ url } ` )
16+ } )
Original file line number Diff line number Diff line change 55# docker network create sesame
66# docker network create reverse # si reverse-proxy externe
77#
8+ # Socket.IO (apps/web/.env) :
9+ # SESAME_APP_API_URL=http://127.0.0.1:4000
10+ # # Si le reverse-proxy route /socket.io vers le port 4000 (API) au lieu du 3000 (Nuxt) :
11+ # # SESAME_APP_PUBLIC_API_URL=https://votre-domaine
12+ #
13+ # Reverse-proxy : router /socket.io vers le port 3000 (Nuxt proxifie vers l'API)
14+ # ou directement vers le port 4000 (définir SESAME_APP_PUBLIC_API_URL ci-dessus).
15+ #
816# Démarrage :
917# docker compose -f docker-compose.prod.yml up -d
1018
You can’t perform that action at this time.
0 commit comments