socketio / socketio/socket.io

On aws server side getting 404 not found error

Open
#4,803 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
63.2k
Forks
10.3k
Avg merge
11d 20h
Merged PRs (30d)
2

Description

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

REQUEST HEADER

Request URL:
https://mywsbackend.tech/socket.io/?EIO=4&transport=polling&t=OeD7QRi
Request Method:
GET
Status Code:
404
Remote Address:
#########
Referrer Policy:
strict-origin-when-cross-origin

:Authority:
mywsbackend.tech
:Method:
GET
:Path:
/socket.io/?EIO=4&transport=polling&t=OeD7QRi
:Scheme:
https
Accept:
*/*
Accept-Encoding:
gzip, deflate, br
Accept-Language:
en-US,en;q=0.9
Origin:
http://localhost:3000
Referer:
http://localhost:3000/
Sec-Fetch-Dest:
empty
Sec-Fetch-Mode:
cors
Sec-Fetch-Site:
cross-site

everything is working fine in local getting issue in aws server only please help to fix this!

Originally posted by @sampete1997 in https://github.com/socketio/socket.io/issues/3615#issuecomment-1684912436

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The payload provides no repository file or test entry point. Start by comparing the shown Express/http server and socket.io client connection with the AWS deployment, then inspect the logged /socket.io polling request; done means the deployed endpoint no longer returns 404 and establishes a connection.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, node.js, react, typescript
Domain
backend, cloud, frontend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.