Hide the URL parameters that are sent from a node server - node.js

I send parameters from a html form to my node js server.
Picture Form
In my server I receive the data in the next way:
Picture Server
So far all is good, but now I want to open a web page without the parameters that I have received before,in other way I want that the parameters are not visible in the URL for the users, in the moment that I open a page using “res.redirect” are seen in the browser as:
https://miDominio.com/room.html?idUsuario=user1&nombreRoom=room1
and I would like that the parameters that I pass are not to visible. I want the next way:
https://miDominio.com/room.html
Do you know how can I do this ?

Related

Storing data from a form using nodejs and express

I need to get some data from a form as POST request and save that data so i can use it on another page.
I am successful at retrieving the data form the form as JSON, but since i am not using any database, i am not able to see the data that i retrieved from the form when i redirect for the next page..
I am new at using jade, nodejs and express. I'd like a opinion on how to retrieve the data that i've sent via post method.
If i use render, it loads the page with all the correct info, but if i reload or change to another page, the data will simple disappear.
You can use Redux Persist (state management tool) or local storage to save data. Both of these will save your data in a way that it can be retrieved when you navigate to the next page or even if you reload your page.

Is there a difference in a fetch request body when its created from a user typing the url and when its created from a clicked link?

I have a project that uses React but server rendered. When a client requests an initial page of the website by writing the URL in the search field, the server.js uses renderToString() to stringify the react App.js (with some initial data added) and send it to the client along with the bundle.js and css. From this point onwards, React takes over, the client will navigate through the app without needing an initial data anymore. Whenever they navigate to a different component, componentDidMount() will request for the corresponding data from the same server.js.
The problem is that I cannot distinguish between a GET request from a componentDidMount() and from the user typing the URL in the search bar. This is crucial for knowing when to send a new markup with an initial data and when to just send a response object.
Right now I am using a very crude method of attaching a querystring in the GET request from the componentDidMount() to identify that it requires a non-initial data/that the request is not an initial request on entering the website.
This method is very messy as in one instance for example, upon refreshing, the non-initial query stays in the url but since its refreshed, it throws all the cached react app, and it then receives the non-initial data displayed nakedly in the browser.
Is there a better way of doing this? Maybe there is an attached information in the fetch get request that shows where the GET request is generated (whether from a clicked link or a typed URL)?

node js asking browser to reload the page

I want to reload the page after some validations placed at the server side fails.. i have already tried with res.redirect res.location and location.reload() .
I need to place the reloading logic on the server side in nodeJS.
So whenever there is a request from client side this validation gets triggered and if the validation fails i am destroying the window user object but i am unable to reload the page...it's stays on the same same and then all services starts failing..because of user object check now..
If you do an ajax call you need to reload in the client side browser code based on http response.
if it's a form post you can render whatever html you want back to the client.
A way to build this in your ajax framework would be to: In serverside you could redirect and then clientside, have the code that looks like this (warning this is just psuedo code):
if(response.httpStatusCode == 301 or 302)
window.location(response.headers.location)

Cannot request Iron Router server route twice without refreshing the client

I am calling a meteor method, which generates a file using fs. I wait for a callback giving me the path where the file exists, and then I request the file with a server route. The code is very similar to this SO answer. I have also tried using createReadStream (as demonstrated here) instead of passing the file directly to response.write.
This all works well on the client's first click of my export/download button. However, if for some reason they want to click the button more than once, the file will get generated but the file will not get served by Iron Router. There are no errors on the client or server. If the user refreshes the client, then the feature will work again (once).
Why do I need to refresh the browser in order to request the same server route a second time? Am I doing something wrong?
Example Application
Does the URL change when they click the first download? If so, and the second route is the same, you will not get redirected as you are already there. If this is the case, can you use the router hooks to send the user back to the route they came from?

how to set query variables on server response

I am running an express app and in a section I need to pass the page I'm serving some data. I am sending the file with the res.sendFile() function. I would prefer it to be in the form of query parameters, so that the page being sent is able to read them easily.
I am unable to run any templating tool or set cookies since the files are part of a cdn uploaded by users, so the information has to be contained so that it is not easily read by other files also served from my server.
Query parameters can only be sent by doing a redirect where your server returns a 3xx status (probably 302) which redirects the browser to a different URL with the query parameters set. This is not particularly efficient because it requires an extra request from the server. See res.redirect() for more info.
A more common way to give data to a browser is to set a few Javascript variables in the web page and the client Javascript can then just read those variables directly. You would have to switch from res.sendFile() to something that can modify specific parts of the web page before sending it - probably one of the many template engines available for Express (jade, handlebars, etc...).
You could also send data by returning a cookie with the response, though a cookie is not really the ideal mechanism for variables just for one particular instance of one particular page.

Resources