I'm getting a server error while deploying backend to railway

Viewed 19

I have recently created a Socket.io ReactJS and ExpressJS web application chat room which works perfectly fine locally, but always runs into problems when I deploy the server backend to either of heroku or railway.app I prefer railway.app to heroku, here are the build and deploy logs

This is the server error which shows when i open the domain provided by railway.app [![This is the server error which shows when i open the domain provided by railway.app][1]][1]

This is the deploy logs [![This is the deploy logs][2]][2]

==============
Using Nixpacks
==============
 
╔═════════ Nixpacks v0.4.4 ═════════╗
║ setup      │ nodejs-16_x, npm-8_x ║
║───────────────────────────────────║
║ install    │ npm ci               ║
║───────────────────────────────────║
║ build      │                      ║
║───────────────────────────────────║
║ start      │ npm run start        ║
╚═══════════════════════════════════╝
 
 
#2 [internal] load .dockerignore
#2 sha256:8217f19b821abdf19d845b1bb60f685cd3b2f48acd88fcc3eec029a8d780d3d2
 
#2 transferring context:
 
#2 transferring context: 2B done
 
#2 ...
 
#1 [internal] load build definition from Dockerfile
 
#1 sha256:a557d5063e3b519cb94949211bac88b303e9cef14770f078d5fe0ca3fff16dfd
#1 transferring dockerfile: 1.27kB done
#1 DONE 0.5s
 
 
#2 [internal] load .dockerignore
#2 sha256:8217f19b821abdf19d845b1bb60f685cd3b2f48acd88fcc3eec029a8d780d3d2
#2 DONE 0.6s
 
 
#3 [internal] load metadata for ghcr.io/railwayapp/nixpacks:debian-1662422726
#3 sha256:02e5e02b458a1a1a602a2f47b42ef27d0d28e2f62e94adec01c0581a1aab4058
 
#3 DONE 0.2s
 
 
#4 [stage-0 1/9] FROM ghcr.io/railwayapp/nixpacks:debian-1662422726@sha256:ac27b084ba99f7566c0940a6a62ac9510bcb811a441428425a89106cc7e335ff
#4 sha256:0571b8b270e4bddae60fd6c38b6d6572b259671716b106139d7d87635de279cd
#4 DONE 0.0s
 
#5 [stage-0 2/9] WORKDIR /app/
#5 sha256:6c52b508395e4a152cb75ff415f9884acc6cca0180f0aeec8385e102bd0d8bc7
#5 CACHED
 
#6 [internal] load build context
#6 sha256:4228640b4b41842ad88c68a12c9c647c4cd5d0914d86a78c10790fb728dcf6c7
#6 transferring context: 80.75kB done
 
#6 DONE 0.1s
 
#7 [stage-0 3/8] COPY .nixpacks/setup.nix .nixpacks/setup.nix
#7 sha256:90a219320e354bb8b46651e22a69e1a2e0556f8d9562533937eef1feacb75c27
#7 CACHED
 
#8 [stage-0 4/8] RUN nix-env -if .nixpacks/setup.nix && nix-collect-garbage -d
#8 sha256:1ca44183429829e48728aa33b9bb8bc66ea4e6b8d9cd3c1be787885d1cc5b684
#8 CACHED
 
#9 [stage-0 5/8] RUN printf '\nPATH=/app/node_modules/.bin:$PATH' >> /root/.profile
#9 sha256:31dc53e4a00e7cb7f7f2f8c68414eadc2d0b3f2a7ef48b29920aa3f3faec07fe
 
#9 DONE 2.0s
 
#10 [stage-0 6/8] COPY . /app/
#10 sha256:161c4078d46f9b012572b06d978ca5ce39c286674d141b73801e2829dc1bdc61```

The following is my server side backend code 

//LIBRARIES
const express = require("express");
const app = express();
const http = require("http"); //comes with express
const cors = require("cors");
const { Server } = require("socket.io"); //curly braces since it comes under socket.io library

//RESOLVES ERRORS
app.use(cors());

//CREATE SERVER
const server = http.createServer(app); //pass an express app in the parameter

//INSTANTIATE SOCKET.IO CONNECTION
const io = new Server(server, { //creates a new instance of the http server
    cors : { //SOLVES MAJOR CORS ERRORS AFTER THE UPDATE
        origin : "http://localhost:3000", //ReactJS runs on port 3000 //https://connect-socketio-devsoc.netlify.app
        methods : ["GET", "POST"], //work only with these methods
    },
}); 

// LISTEN TO CONNECTION OR DISCONNECT EVENTS
io.on("connection", (socket) => { //listens to connections
    console.log(`User connected : ${socket.id}`); //logs the ID of users who connected

    socket.on("join_room", (data) => { //accepts the room ID from the frontend
        socket.join(data); //joins the room
        console.log(`User with ID : ${socket.id} joined room ID : ${data}`)
    });

    socket.on("send_message", (data) => {
        socket.to(data.room).emit("receive_message", data);
    });

    socket.on("disconnect", () => { //listens to disconnect events
        console.log("User disconnected.", socket.id); //logs the ID of users who disconnected
    })
});

//RUN SERVER
server.listen(3001, () => { //port 3001 since ReactJS runs on port 3000
    console.log("Server running."); //acknowledgement that the server is running
});

the following is my client side frontend

    const socket = io.connect("https://connect-production.up.railway.app");


Any help would be greatly appreciated


  [1]: https://i.stack.imgur.com/qgWpd.png
  [2]: https://i.stack.imgur.com/rIEdu.png
0 Answers
Related