I'm looking for a way, in Cowboy, to map arbitrary paths (stored in the database) to specific blog posts.
That is: I've got a few thousand blog posts, which are accessible via a few names each, such as the canonical URL (e.g. /post/42), some aliases (e.g. /2013/11/25/erlang-rocks), historical locations (e.g. /path-on-old-blog/12345), etc.
I know that I could simply use a catch-all route:
{ "/[...]", catch_all_handler, [] },
...and then look up the path in the database, but I was considering creating the routes from the database, as follows:
Posts = posts:all(),
Paths = [get_handlers_for_post(P) || P <- Posts],
Routes = lists:flatten(Paths),
get_handler_for_post(P) ->
% Generate a list of paths with IDs from the database.
% Return something that looks like this:
% [{"/canonical/1", post_handler, [1]},
% {"/first-alias", post_handler, [1]}].
% TODO: code goes here...
That is: put all the possible paths in the router, pointing to the same handler, each with the ID of the post.
The question is: Is this sensible? How many routes does cowboy support?