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}');
});
6 Replies
Project ID:
ceb900e2-1342-4ba2-8205-0f2445af5638
ceb900e2-1342-4ba2-8205-0f2445af5638
Solution
const port = process.env.PORT || 3000;
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?
correct
wow thats great, ty