mardi 4 août 2015

Express using a patternless dynamic base URL to render different pages

I am interested in having a route that could respond to a request with a file eg express's res.sendFile() based on the URL's base parameter i.e. http://ift.tt/1P4lZhD. The problem is that the URLs are completely user generated and completely dynamic. Similar to that of Github, http://ift.tt/1M3etU0 could render a user's profile or http://ift.tt/1P4lZxT could render a project—but they are both strings that don't have a pattern and the machine has no way of knowing that http://ift.tt/1M3etU0 refers to a user view unless it does some type of check.

app.all('/*', function(req, res) {
res.sendfile('index.html', { root: config.server.distFolder });

Github responds to server requests with different views based on the parameter, even though they have no predefined pattern.

i.e. it would be easy to know that http://ift.tt/1M3euYh is a user route and the server can respond with a user view (the pattern to match would be http://ift.tt/1P4lZxY But when the string is completely dynamic it becomes more difficult. (How does express know if it should respond with a user or a project view with a url like example.com/cococola)?

I believe you would somehow be able to check the URL parameter, understand that it refers to (in this case) either a project or a user's page, and then render that view. How do you do this without making a synchronous call and forcing the user to wait for the server to check what view-type the parameter string refers to before responding?

I'm using angular, are there other ways to respond to server requests with different pages based on URL's that have no predeterminable matching pattern? The reason being that, I would like to separate my site into many different apps. http://ift.tt/1gZKM9B might require a user's profile SPA, whereas http://ift.tt/1P4lZy2 might require a user's project SPA—but, as these are user defined, there is no way to respond based on the parameter's matching pattern. Would like to keep the URL as minimal as possible :-)

Any help is appreciated. Thanks :-)

Aucun commentaire:

Enregistrer un commentaire