diff --git a/frontend/src/pages/chat/chat.ts b/frontend/src/pages/chat/chat.ts index 06f371a..287df81 100644 --- a/frontend/src/pages/chat/chat.ts +++ b/frontend/src/pages/chat/chat.ts @@ -3,12 +3,19 @@ import { showError } from "@app/toast"; import authHtml from './chat.html?raw'; import client from '@app/api' import { updateUser } from "@app/auth"; - import io from "socket.io-client" -const socket = io("https://localhost:8888"); + + +// const socket = io("wss://localhost:8888"); + +const socket = io("wss://localhost:8888", { + path: "/app/chat/socket.io/", + secure: false, + transports: ["websocket"], +}); // Listen for the 'connect' event -socket.on("connect", async() => { +socket.on("connect", () => { console.log("Connected to the server: ", socket.id); // Send a message to the server socket.send("Hello from the client: " + `${socket.id}`); diff --git a/nginx/conf/locations/chat.conf b/nginx/conf/locations/chat.conf index 57d3be2..8a7ea02 100644 --- a/nginx/conf/locations/chat.conf +++ b/nginx/conf/locations/chat.conf @@ -3,7 +3,7 @@ location /api/chat/ { proxy_pass http://chat; } -location /api/socket.io/ { +location /api/chat/socket.io/ { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; diff --git a/src/chat/src/routes/nginx-chat.ts b/src/chat/src/routes/nginx-chat.ts index 522d246..05a7ee4 100644 --- a/src/chat/src/routes/nginx-chat.ts +++ b/src/chat/src/routes/nginx-chat.ts @@ -1,42 +1,17 @@ import { FastifyPluginAsync } from 'fastify'; import { MakeStaticResponse, typeResponse } from '@shared/utils'; import { Type } from '@sinclair/typebox'; - import Fastify from 'fastify' import { Server } from "socket.io" -// import path from 'path' -// import fastifyStatic from '@fastify/static' -// import fs from 'fs/promises' - - -// import { fileURLToPath } from 'url'; -// import { dirname } from 'path'; - - - -// const __filename = fileURLToPath(import.meta.url); -// const __dirname = dirname(__filename); - -// const fastifyWS = Fastify({ -// logger: true -// }) - - - -// fastify.register(fastifyStatic, { -// root: path.join(__dirname, ''), prefix: '/' -// }) - -// const io = new Server(8888, { -// cors: { -// origin: "*", -// } -// }) +import { Socket } from "socket.io"; const fastify = Fastify(); -const io = new Server(fastify.server, { cors: { origin: "*" } }); -import { Socket } from "socket.io"; + +const io = new Server(fastify.server, { + path: "/app/chat/socket.io/", + cors: { origin: "*" }, +}); @@ -49,10 +24,6 @@ io.on("connection", (socket: Socket) => { }); - - - - export const ChatRes = { 200: typeResponse('success', 'chat.success', { name: Type.String(),