diff --git a/backend/src/index.js b/backend/src/index.js index 7a4678c..8e130b9 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -17,6 +17,7 @@ if (process.env.NODE_ENV) { const app = express(); const httpServer = createServer(app); const io = new Server(httpServer, { + path: '/api/socket.io', cors: { origin: true, credentials: true, @@ -86,4 +87,4 @@ app.get("/api/status", (req, res) => { const PORT = process.env.PORT || 5000; httpServer.listen(PORT, () => { console.log("Server running on port 5000"); -}); \ No newline at end of file +}); diff --git a/frontend/app/composables/useApi.ts b/frontend/app/composables/useApi.ts index 9da341b..4a98fc7 100644 --- a/frontend/app/composables/useApi.ts +++ b/frontend/app/composables/useApi.ts @@ -1,9 +1,13 @@ // composables/useApi.js import { ref } from 'vue' +function normalizeUrl(url: string): string { + return url.replace(/\/+$/, '') +} + export default function useApi() { const config = useRuntimeConfig() - const baseUrl = config.public.apiBaseUrl + const baseUrl = `${normalizeUrl(config.public.apiBaseUrl)}/api` // Generic GET request const get = async (endpoint) => { diff --git a/frontend/app/composables/useSocket.ts b/frontend/app/composables/useSocket.ts index a6fc4fb..a78e57d 100644 --- a/frontend/app/composables/useSocket.ts +++ b/frontend/app/composables/useSocket.ts @@ -1,9 +1,13 @@ import { ref, onUnmounted } from 'vue' import { io } from 'socket.io-client' +function normalizeUrl(url: string): string { + return url.replace(/\/+$/, '') +} + export default function useSocket() { const config = useRuntimeConfig() - const socketUrl = `${config.public.apiBaseUrl.replace('/api', '')}` + const apiBaseUrl = normalizeUrl(config.public.apiBaseUrl) const socket = ref(null) const isConnected = ref(false) @@ -11,7 +15,8 @@ export default function useSocket() { function initSocket() { if (socket.value) return - const s = io(socketUrl, { + const s = io(apiBaseUrl, { + path: '/api/socket.io', transports: ['websocket', 'polling'], reconnection: true, reconnectionAttempts: 10, diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts index 298abc5..1623381 100644 --- a/frontend/nuxt.config.ts +++ b/frontend/nuxt.config.ts @@ -13,7 +13,7 @@ export default defineNuxtConfig({ runtimeConfig: { public: { - apiBaseUrl: process.env.API_BASE_URL || 'http://localhost:5000/api' + apiBaseUrl: process.env.API_BASE_URL || 'http://localhost:5000' } }, @@ -45,4 +45,4 @@ export default defineNuxtConfig({ }, modules: ['@nuxtjs/i18n', '@nuxt/content', '@nuxt/image'] -}) \ No newline at end of file +})