Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda