You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi
I have node js server with express and react js client in local. in local socket io is working fine but when i deployed to aws ec2 instance I am getting 404 status error
server
import express, { Express, Response, Request, NextFunction } from "express";
import bodyParser from "body-parser";
import cors from "cors";
import ErrorHandler from "./utils/errorHandler";
import MongoService, { Collections } from "./utils/mongo";
import http from 'http'
import socketIO from "socket.io";
const app: Express = express();
const PORT = process.env.PORT;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ limit: "1mb" }));
app.use(cors());
const server = http.createServer(app);
export const io = new socketIO.Server(server, {
cors: {
origin: "*",
methods: ["GET", "POST"],
},
});
io.on("connection", (socket) => {
console.log(
"connection successful! \n user connected ID: ",
socket.id,
"\n"
);
socket.on("disconnect", () => {
console.log("Disconnected", "\n user ID: ", socket.id, "\n");
});
});
export const IO = io;
MongoService.init().then(() => {
server.listen(PORT, async () => {
await seed();
console.log(`Server running at ${PORT}`);
});
});
client
import io from 'socket.io-client';
// export const BACKEND_URL = 'http://localhost:3001';
export const BACKEND_URL = 'https://mywsbackend.tech';
export const socket = io(BACKEND_URL,{withCredentials: false, rejectUnauthorized: false}); //connecting to socket server
socket.on("connect_error", (err) => {
console.log(`connect_error due to ${err.message}`);
});
aws ec2 logs
0|index | GET /socket.io/?EIO=4&transport=polling&t=OeD8PKY 404 149 - 0.493 ms
0|index | GET /socket.io/?EIO=4&transport=polling&t=OeD8PL1 404 149 - 0.417 ms
0|index | GET /socket.io/?EIO=4&transport=polling&t=OeD8Pjr 404 149 - 0.447 ms
0|index | GET /socket.io/?EIO=4&transport=polling&t=OeD8Qme 404 149 - 0.459 ms
0|index | GET /socket.io/?EIO=4&transport=polling&t=OeD8RBb 404 149 - 0.451 ms
0|index | GET / 200 24 - 0.487 ms
0|index | GET /socket.io/?EIO=4&transport=polling&t=OeD8SEW 404 149 - 0.438 ms
0|index | GET /socket.io/?EIO=4&transport=polling&t=OeD8SF0 404 149 - 0.417 ms
I also recommend adding the origin names of what will access your server instead of origin: "*", despite setting the credentials required to false, i'm not sure you can still do a origin wildcard in socket v4.
Hi
I have node js server with express and react js client in local. in local socket io is working fine but when i deployed to aws ec2 instance I am getting 404 status error
server
client
aws ec2 logs
REQUEST HEADER
everything is working fine in local getting issue in aws server only please help to fix this!
Originally posted by @sampete1997 in #3615 (comment)
The text was updated successfully, but these errors were encountered: