express & socket.io ssl support issue
Anonymous
OP

2 years 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)

Closed

20 Replies

maddsua

2 years 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?


maddsua

2 years ago

how does this not availability manifest itself?

a 404 error, connection reset or a railway error page saying that "app failed to respond"?


Anonymous
OP

2 years ago

404 not found


Anonymous
OP

2 years ago

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


maddsua

2 years ago

does this 404 come from the app itself?


maddsua

2 years 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


Anonymous
OP

2 years ago

ok i will add the static assets


Anonymous
OP

2 years 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


maddsua

2 years ago

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


maddsua

2 years ago

I mean, what the router routes to?


Anonymous
OP

2 years 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


maddsua

2 years ago

ok so it's an API


Anonymous
OP

2 years ago

right


Anonymous
OP

2 years ago

{

errno: -111,

code: 'ECONNREFUSED',

syscall: 'connect',

address: '::1',

port: 5432

}


Anonymous
OP

2 years ago

it seems cors issue


Anonymous
OP

2 years ago

i forget to put cors in http


Anonymous
OP

2 years ago

i only put cors is ws


Anonymous
OP

2 years ago

my bad


Anonymous
OP

2 years ago

i will give full code cors in ws and http later


Anonymous
OP

2 years ago

thanks for help


Welcome!

Sign in to your Railway account to join the conversation.

Loading...