socket default acess refuse server
This commit is contained in:
parent
cf6f3145b6
commit
34e9f8e3ca
3 changed files with 17 additions and 39 deletions
|
|
@ -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}`);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue