R
Railway4mo ago
aryabp

express & socket.io ssl support issue

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)
9 Replies
Percy
Percy4mo ago
Project ID: N/A
maddsua
maddsua4mo 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? how does this not availability manifest itself? a 404 error, connection reset or a railway error page saying that "app failed to respond"?
aryabp
aryabpOP4mo ago
404 not found i access the wss:// without port (only url that given by railway)
maddsua
maddsua4mo ago
does this 404 come from the app itself? 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
aryabp
aryabpOP4mo ago
ok i will add the static assets 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
maddsua4mo ago
so, what kind of content should be served via the http part of the app? I mean, what the router routes to?
aryabp
aryabpOP4mo 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
maddsua4mo ago
ok so it's an API
aryabp
aryabpOP4mo ago
right { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '::1', port: 5432 } it seems cors issue i forget to put cors in http i only put cors is ws my bad thanks for help
Want results from more Discord servers?
Add your server