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

265
Visualizações
Rewrite URL parameter when using node.js and express without a redirect

I am using node.js, express, and sockets.io to:

  1. Find out whether or not the user has included a specific URL parameter when they arrive (working)
  2. If not, make a new random room ID and join the user to that room (working)
  3. Modify the address bar of the browser to reflect the new URL without redirecting the browser (unsure if possible, or how to accomplish)

First, I do not know if this is possible without violating DOM security. If it is, I would like to understand how I might be able to do it.

If it is not possible, and/or if I need to use a redirect, could you show me how to do it within my already working code within the working context of items #1 and #2?

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var url = require('url');

app.use(express.static(__dirname + '/node_modules'));

app.get('/', function(req, res, next) {
  res.sendFile(__dirname + '/index.html');
  var roomID = req.query.me;
    if (roomID == null || !io.sockets.adapter.rooms[roomID]) {
      console.log("URL room variable is: " + roomID);
      console.log('New room!');
      roomID = Math.random().toString(36).substring(2, 13);
      joinRoom(roomID);
      console.log("+ you just joined new room: " + roomID);
    } else {
      joinRoom(roomID);
      console.log("URL room variable is: " + roomID);
      console.log("= you just joined existing room: " + roomID);
    }
});

function joinRoom(roomID) {
  io.on('connection', function(socket) {
    socket.join(roomID);
    io.sockets.in(roomID).emit('connectToRoom', "Joined room: http://localhost:3030/?me=" + roomID);
  });
  return;
}

server.listen(3030);

I do not have any sample code for the part that I'm trying to accomplish because I simply don't know where I should begin. So I would appreciate any direction (redirection? pun intended).

Thank you!

about 4 years ago · Santiago Trujillo
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