Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
redirect from http to https on a node.js server

I'm making a small multiplayer game for the browser using node.js and socket.io. I'm not to familiar with the whole HTTP and HTTPS things.

Currently I'm using a Node.js server for the game on port 3000. With this atempt I am only able to host one server at a time. Either a http or a https server. The problem is, that browser always try to access the http server, but it's insecure.

So my question is: Can I redirect the client to https somehow? Or is there a way to remove the port completly and let it run as a page of my Apache for Ubuntu (Like https://example.com/game)?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The first thing would be to determine if you're in HTTP

Example:

const url = new URL('http://example.com')
console.log(url.protocol) // output: "http:"

Then to forward to HTTPS, just redirect.

res.writeHead(301, { Location: `https://${req?.headers.host}/${path}` });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!