R
Railway10mo ago
t4nkup

Node app with Express and websockets using SSL port 443

Hey do we have to use port 3000 for each service? I am building a node app and using express and websockets. I have it setup so they both use the same port but I'm not sure how its all supposed to work since railways creates the SSL certs and also sets the port to 3000. // create our server import express from 'express'; import https from 'https'; import { WebSocketServer } from 'ws'; const site = express(); const server = https.createServer(site); const wss = new WebSocketServer({ server }); // load requests for our homepage site.get('/', function(request, response) { }); // websocket message handling wss.on('connection', (ws) => { }); // have server listen on default HTTPS port (443) const PORT = process.env.PORT || 443; server.listen(PORT, () => { console.log('Server is running on https://localhost:${PORT}'); });
Solution:
const port = process.env.PORT || 3000;
Jump to solution
6 Replies
Percy
Percy10mo ago
Project ID: ceb900e2-1342-4ba2-8205-0f2445af5638
t4nkup
t4nkupOP10mo ago
ceb900e2-1342-4ba2-8205-0f2445af5638
Solution
Brody
Brody10mo ago
const port = process.env.PORT || 3000;
t4nkup
t4nkupOP10mo ago
hey thx for reply Brody. So railways handles all the HTTPS traffic and then converts it to HTTP traffic to my service? So I dont have to worry about HTTPS at all? I can just code my server as if it was using HTTP?
Brody
Brody10mo ago
correct
t4nkup
t4nkupOP10mo ago
wow thats great, ty
Want results from more Discord servers?
Add your server