Skip to content
Advertisement

How to create html file from path entered into url

How do websites like lichess and shrib create specific pages for you to personally use? Examples: http://en.lichess.org/fdnenTEJ -> https://lichess.org/fdnenTEJ
http://shrib.com/uaR3EKNBc8d4OdI -> http://shrib.com/uaR3EKNBc8d4OdI

They generate unique id paths which are associated with new html pages.

How would I implement this in a node js app? I realize this question is very broad and vague, but I’d like a simplified version of how a system like this would work.

Advertisement

Answer

Make a random string until it’s unique, then add to database. Match requests so that random string is a parameter, and use it in the database query.

You might also be tempted to simply encode your database ID as base62 or base64. This is a bad, bad idea, security-wise.

EDIT:

app.get('/:tokenstring', function(request, response, next) {
  // ...
});
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement