Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda