-1

I am trying to build kind of a group chat app. On the homepage, you are told to enter your userID (it can be anything) and a roomID. Multiple people can join a room and interact with each other. I'm using express and ejs

Here is the server side code:

const express = require("express");
const app = express();
const bodyParser = require("body-parser");
server.listen(3000);

app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));

app.get("/", (req, res) => {
    res.render("index");
});

app.post("/", (req, res) => {
    const { roomID, userID } = req.body;
    res.redirect("/" + roomID,{userID}); //how do I also send the userID in this redirect
});

app.get("/:roomID", (req, res) => {
    console.log(req.body.testing);
    res.render("room");
});

I want the userID to be accessible in the room.ejs file to work with it. I don't want to use query strings because I don't want to expose the username in the URL.

  • Does this answer your question? [How do I redirect in expressjs while passing some context?](https://stackoverflow.com/questions/19035373/how-do-i-redirect-in-expressjs-while-passing-some-context) – Lin Du Aug 24 '23 at 03:06

0 Answers0