express & socket.io ssl support issue
Anonymous
TRIALOP

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

maddsua
HOBBY

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?


maddsua
HOBBY

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"?


Anonymous
TRIALOP

a year ago

404 not found


Anonymous
TRIALOP

a year ago

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


maddsua
HOBBY

a year ago

does this 404 come from the app itself?


maddsua
HOBBY

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


Anonymous
TRIALOP

a year ago

ok i will add the static assets


Anonymous
TRIALOP

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


maddsua
HOBBY

a year ago

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


maddsua
HOBBY

a year ago

I mean, what the router routes to?


Anonymous
TRIALOP

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


maddsua
HOBBY

a year ago

ok so it's an API


Anonymous
TRIALOP

a year ago

right


Anonymous
TRIALOP

a year ago

{

errno: -111,

code: 'ECONNREFUSED',

syscall: 'connect',

address: '::1',

port: 5432

}


Anonymous
TRIALOP

a year ago

it seems cors issue


Anonymous
TRIALOP

a year ago

i forget to put cors in http


Anonymous
TRIALOP

a year ago

i only put cors is ws


Anonymous
TRIALOP

a year ago

my bad


Anonymous
TRIALOP

a year ago

i will give full code cors in ws and http later


Anonymous
TRIALOP

a year ago

thanks for help


Loading...