express & socket.io ssl support issue

AnonymousTRIAL

a year ago

require('dotenv').config()
const express = require('express');
const cors = require('cors');
const http = require('http');
const userRouter = require('./router/router')
const socketIo = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socketIo(server, {
cors: {
origin: '*'
}
});

app.use(cors());
app.use(express.json())
app.use(express.urlencoded({ extended: false }));
app.use('/', userRouter);
app.set('trust proxy', true);

const port = process.env.PORT || 4000;
server.listen(port, () => {
console.log(Express server listening on port ${port});
});

when i deploy the code why only wss service that available in railway given url? why https can't be accessed? ( plain http/ws still works)

0 Replies

maddsuaHOBBY

a year ago

do I get this right:
when you are running on a local machine (no TLS), both ws and http can be accessed from the same port (4000 in case of the code above)
but when deployed to railway somehow http stops working?


maddsuaHOBBY

a year ago

how does this not availability manifest itself?
a 404 error, connection reset or a railway error page saying that "app failed to respond"?


AnonymousTRIAL

a year ago

404 not found


AnonymousTRIAL

a year ago

i access the wss:// without port (only url that given by railway)


maddsuaHOBBY

a year ago

does this 404 come from the app itself?


maddsuaHOBBY

a year ago

if so, it is likely that during deploy the static assets that were meant to be served by the app were not included for some reason


AnonymousTRIAL

a year ago

ok i will add the static assets


AnonymousTRIAL

a year ago

ok the trigger of https routes already found in console.log(), idk what's going on but i change the ver into legacy and then change the version into v2 again


maddsuaHOBBY

a year ago

so, what kind of content should be served via the http part of the app?


maddsuaHOBBY

a year ago

I mean, what the router routes to?


AnonymousTRIAL

a year ago

it looks like this
const express = require('express')
const router = express.Router()
const userController = require('../controller/userController')
const Auth = require('../middleware/auth')

router.post('/signup',userController.signup)

router.post('/login',userController.login)

router.post('/logout',Auth.verifyToken,userController.logout)

router.post('/verify',Auth.verifyToken,userController.verify)

router.post('/otp',userController.otp)

router.post('/ubah',userController.ubah)

router.post('/hapus',userController.hapus)

router.post('/lupa',userController.lupa)

router.get('/getcategory',userController.getcategory)

router.get('/getproduct',userController.getproduct)

router.post('/insertpesan',userController.insertpesan)

router.post('/getpesan',userController.getpesan)
module.exports = router


maddsuaHOBBY

a year ago

ok so it's an API


AnonymousTRIAL

a year ago

right


AnonymousTRIAL

a year ago

{

errno: -111,

code: 'ECONNREFUSED',

syscall: 'connect',

address: '::1',

port: 5432

}


AnonymousTRIAL

a year ago

it seems cors issue


AnonymousTRIAL

a year ago

i forget to put cors in http


AnonymousTRIAL

a year ago

i only put cors is ws


AnonymousTRIAL

a year ago

my bad


AnonymousTRIAL

a year ago

i will give full code cors in ws and http later


AnonymousTRIAL

a year ago

thanks for help


express & socket.io ssl support issue - Railway Help Station