简体   繁体   中英

http headers in express with node.js for loading content

I'm working on a DHTML code playground for fun. Right now, to pull the code that will be in the textareas from my database, I use client side javascript

var currentURL = (document.URL);
var part = currentURL.split("com/")[1]; 

So this gets what's after the "com/" in my url, which should be a hash id, and stores that into the "part" variable as shown above. The rest of my code uses that "part" variable which is the hash id I have, and queries my db looking for the content to pull up with that matching hash id. This is fine. It works, however, since I'm now working with Express.js, node.js and jade, I'm wondering if I should use the request object instead so when visiting myurl.com/hashid, I then get the content from my db. Is using a server side solution like this better than my current solution?

If I have understood this question correctly then the answer is yes. You should use something like req.params.hashId on server side. There is no need to extract it on client side if you only need it to query the db on server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM