Sam (caffeine)
Sam (caffeine)
RRailway
Created by Sam (caffeine) on 3/25/2024 in #✋|help
Express & WebSockets - wss connection failed.
I will keep digging. This one is a weird one. Thanks for the help in the meantime.
16 replies
RRailway
Created by Sam (caffeine) on 3/25/2024 in #✋|help
Express & WebSockets - wss connection failed.
I do have error listeners in both the client and the server as also making sure Im using the web socket for transport. I suspect the websocket closes shortly after refreshing for some reason. Is there any way to send a keep alive signal or any other recommendation?
16 replies
RRailway
Created by Sam (caffeine) on 3/25/2024 in #✋|help
Express & WebSockets - wss connection failed.
yes, let me give it a shot.
16 replies
RRailway
Created by Sam (caffeine) on 3/25/2024 in #✋|help
Express & WebSockets - wss connection failed.
Yes, I can confirm both and the client are using the same socket.io version
16 replies
RRailway
Created by Sam (caffeine) on 3/25/2024 in #✋|help
Express & WebSockets - wss connection failed.
sent via dm
16 replies
RRailway
Created by Sam (caffeine) on 3/25/2024 in #✋|help
Express & WebSockets - wss connection failed.
I cannot seem to find more information about that error. I'm confused as it does not disclose any extra info. When you say a link, do you mean a link to my application?
16 replies
RRailway
Created by Sam (caffeine) on 3/25/2024 in #✋|help
Express & WebSockets - wss connection failed.
Any help would be appreaciated ❤️
16 replies
RRailway
Created by Sam (caffeine) on 3/25/2024 in #✋|help
Express & WebSockets - wss connection failed.
e06a1209-8d68-4c30-a8dc-bee27085cfa7
16 replies
RRailway
Created by Sam (caffeine) on 3/25/2024 in #✋|help
Express & WebSockets - wss connection failed.
I'm using the railway domain for my development version as also a custom domain configured with railway. This is my current code snippet for my websocket implementation in the backend.
const express = require('express');
const cors = require('cors');
const { createServer } = require('http'); // Ensure this is at the top with other requires
const { Server } = require('socket.io');
const axios = require('axios');
const Redis = require('ioredis');
const userSockets = new Map();

// CONFIG //
require('dotenv').config();
const stripe = Stripe(process.env.STRIPE_SECRET_KEY);

const app = express();
const corsOptions = {
origin: 'https://dev-noisse.vercel.app', // Replace with your frontend domain
methods: ['GET', 'POST'], // Specify the allowed HTTP methods
allowedHeaders: ['Content-Type'], // Specify the allowed headers
credentials: true // Allow sending cookies
};
app.use(cors(corsOptions));
const httpServer = createServer(app);

const io = new Server(httpServer, {
cors: {
origin: "https://dev-noisse.vercel.app",
methods: ["GET", "POST"],
},
pingTimeout: 60000, // Increase the ping timeout to 60 seconds
pingInterval: 25000 // Send a ping every 25 seconds
});

io.on('connection', (socket) => {
console.log('a user connected');

socket.on('authenticate', (hunter_id) => {
// Validate hunter_id here if necessary
userSockets.set(hunter_id, socket.id);
});

socket.on('disconnect', () => {
for (const [hunter_id, socketId] of userSockets.entries()) {
if (socketId === socket.id) {
userSockets.delete(hunter_id);
console.log(`User with hunter_id ${hunter_id} disconnected`);
break;
}
}
});
});
......

const PORT = process.env.PORT || 3001;
httpServer.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
io.attach(httpServer);
});
]
const express = require('express');
const cors = require('cors');
const { createServer } = require('http'); // Ensure this is at the top with other requires
const { Server } = require('socket.io');
const axios = require('axios');
const Redis = require('ioredis');
const userSockets = new Map();

// CONFIG //
require('dotenv').config();
const stripe = Stripe(process.env.STRIPE_SECRET_KEY);

const app = express();
const corsOptions = {
origin: 'https://dev-noisse.vercel.app', // Replace with your frontend domain
methods: ['GET', 'POST'], // Specify the allowed HTTP methods
allowedHeaders: ['Content-Type'], // Specify the allowed headers
credentials: true // Allow sending cookies
};
app.use(cors(corsOptions));
const httpServer = createServer(app);

const io = new Server(httpServer, {
cors: {
origin: "https://dev-noisse.vercel.app",
methods: ["GET", "POST"],
},
pingTimeout: 60000, // Increase the ping timeout to 60 seconds
pingInterval: 25000 // Send a ping every 25 seconds
});

io.on('connection', (socket) => {
console.log('a user connected');

socket.on('authenticate', (hunter_id) => {
// Validate hunter_id here if necessary
userSockets.set(hunter_id, socket.id);
});

socket.on('disconnect', () => {
for (const [hunter_id, socketId] of userSockets.entries()) {
if (socketId === socket.id) {
userSockets.delete(hunter_id);
console.log(`User with hunter_id ${hunter_id} disconnected`);
break;
}
}
});
});
......

const PORT = process.env.PORT || 3001;
httpServer.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
io.attach(httpServer);
});
]
16 replies