This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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']
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user