@@ -7,21 +7,15 @@ import setupApp from './src/server/extension.setup'
77import { loadingBarHijackFilter } from './src/composables/useLoadingBarHijackFilter'
88
99const SESAME_APP_API_URL = process . env . SESAME_APP_API_URL || 'http://127.0.0.1:4000'
10- const SESAME_APP_API_URL_PARSED = new URL ( SESAME_APP_API_URL )
11- /** URL API exposée au navigateur (WebSocket). Ex. http://mactacx:4002 (Docker) ou :4000 (API native). */
12- const SESAME_APP_PUBLIC_API_URL = process . env . SESAME_APP_PUBLIC_API_URL || ''
13- /** Port API vu depuis le navigateur (Docker : 4002 mappé, interne API : 4000). */
14- const SESAME_APP_PUBLIC_API_PORT = process . env . SESAME_APP_PUBLIC_API_PORT || ''
1510const SESAME_ALLOWED_HOSTS = process . env . SESAME_ALLOWED_HOSTS ? process . env . SESAME_ALLOWED_HOSTS . split ( ',' ) : [ ]
16- const SOCKET_IO_PROXY_TARGET = SESAME_APP_API_URL . replace ( / \/ $ / , '' )
11+ const API_PROXY_TARGET = SESAME_APP_API_URL . replace ( / \/ $ / , '' )
1712const IS_DEV = process . env . NODE_ENV === 'development'
1813
1914if ( SESAME_ALLOWED_HOSTS . length === 0 && ! / l o c a l h o s t / . test ( SESAME_APP_API_URL ) && IS_DEV ) {
2015 SESAME_ALLOWED_HOSTS . push ( new URL ( SESAME_APP_API_URL ) . hostname )
2116}
2217
2318consola . info ( `[Nuxt] SESAME_APP_API_URL: ${ SESAME_APP_API_URL } ` )
24- consola . info ( `[Nuxt] Socket.IO public port: ${ SESAME_APP_PUBLIC_API_PORT || SESAME_APP_API_URL_PARSED . port || '4000' } ` )
2519consola . info ( `[Nuxt] SESAME_ALLOWED_HOSTS: ${ SESAME_ALLOWED_HOSTS } ` )
2620
2721let SESAME_APP_DARK_MODE : 'auto' | boolean = false
@@ -84,17 +78,14 @@ export default defineNuxtConfig({
8478 runtimeConfig : {
8579 public : {
8680 release : process . env . npm_package_name + '@' + process . env . npm_package_version ,
87- socketApiUrl : SESAME_APP_PUBLIC_API_URL ,
88- socketApiPort : SESAME_APP_API_URL_PARSED . port || ( SESAME_APP_API_URL_PARSED . protocol === 'https:' ? '443' : '4000' ) ,
89- socketPublicApiPort : SESAME_APP_PUBLIC_API_PORT || SESAME_APP_API_URL_PARSED . port || ( SESAME_APP_API_URL_PARSED . protocol === 'https:' ? '443' : '4000' ) ,
90- socketApiProtocol : SESAME_APP_API_URL_PARSED . protocol ,
9181 sentry : {
9282 dsn : process . env . SESAME_SENTRY_DSN ,
9383 } ,
9484 } ,
9585 } ,
9686 modules : [
9787 '@sentry/nuxt/module' ,
88+ '@nuxt-alt/proxy' ,
9889 '@nuxt-alt/auth' ,
9990 '@nuxt-alt/http' ,
10091 '@pinia/nuxt' ,
@@ -105,6 +96,21 @@ export default defineNuxtConfig({
10596 'nuxt-monaco-editor' ,
10697 ...setupApp ( ) ,
10798 ] ,
99+ proxy : {
100+ debug : IS_DEV ,
101+ experimental : {
102+ listener : true ,
103+ } ,
104+ proxies : {
105+ '/api' : {
106+ target : API_PROXY_TARGET ,
107+ changeOrigin : true ,
108+ ws : true ,
109+ xfwd : true ,
110+ rewrite : ( path : string ) => path . replace ( / ^ \/ a p i / , '' ) ,
111+ } ,
112+ } ,
113+ } ,
108114 sentry : {
109115 autoInjectServerSentry : "top-level-import" ,
110116 } ,
@@ -187,7 +193,7 @@ export default defineNuxtConfig({
187193 color : 'primary' ,
188194 size : '3px' ,
189195 position : 'top' ,
190- /** Exclut socket.io (long-polling ) et le polling de synchro / daemon. */
196+ /** Exclut Socket.IO (`/api/socket.io` ) et le polling de synchro / daemon. */
191197 hijackFilter : loadingBarHijackFilter ,
192198 } ,
193199 } ,
@@ -206,11 +212,13 @@ export default defineNuxtConfig({
206212 vite : {
207213 server : {
208214 allowedHosts : [ 'localhost' , ...SESAME_ALLOWED_HOSTS ] ,
215+ // En dev, le navigateur parle à Vite : seul Vite peut faire l'upgrade WS (Nitro proxy.web → Invalid frame header).
209216 proxy : {
210- '/socket.io' : {
211- target : SOCKET_IO_PROXY_TARGET ,
217+ '/api/ socket.io' : {
218+ target : API_PROXY_TARGET ,
212219 changeOrigin : true ,
213220 ws : true ,
221+ rewrite : ( path : string ) => path . replace ( / ^ \/ a p i / , '' ) ,
214222 } ,
215223 } ,
216224 } ,
@@ -262,17 +270,9 @@ export default defineNuxtConfig({
262270 typescriptBundlerResolution : true ,
263271 } ,
264272 nitro : {
265- devProxy : {
266- '/socket.io' : {
267- target : SOCKET_IO_PROXY_TARGET ,
268- changeOrigin : true ,
269- ws : true ,
270- } ,
271- } ,
272- routeRules : {
273- '/api/**' : {
274- proxy : `${ SESAME_APP_API_URL } /**` ,
275- } ,
273+ experimental : {
274+ /** Requis par @nuxt-alt/proxy pour ne pas intercepter les upgrades WS. */
275+ websocket : false ,
276276 } ,
277277 } ,
278278 experimental : {
0 commit comments