MisterD
Hi,
I was thinking about simple user settings for Permalinks.
Something like Wordpress has: Customize permalinks – Documentation – WordPress.org
The question is - how to make same behaviour in Phoenix ?
In case of predefined route structures - everything is clear, you simple make predefined routes in advance.
But what about custom one ?
- How to make a new route structure from user input ?
- How to add a new route programmatically ?
To my understanding the routes are build during compilation time, but does it mean it is not possible to create during runtime ?
If so then, what would the solution ?
- Load routes from DB during compilation time and then if new routes are added - restart everything ?
Any ideas or an advice is very much welcome !
Trending in Questions
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Other Trending Topics
Hi everyone,
Over several Elixir projects I kept writing down what each one taught me and turning the setups I got right into something ...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #performance










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
easco
Just a thought off the top of my head. The Phoenix Router is “just a plug”. It tends to be the Plug at the end of the pipeline, but it is still a Plug. So it seems you could develop a Plug that looks up a new route in a dynamic data source (an ETS table, or database).
MisterD
Thank you for reply!
I was thinking this way too…
I already tried to create a Plug and added that to the Pipeline.
I thought that I can analyse requested url and match through the regexp.
Once matched forward it to required function (handler).
But the problem is the following:
MisterD
I suppose the question is - during Plug execution, how to connect to the point when Phoenix analyses existing routes and give it the new route taken from DB or User Input ?
LostKobrakai
You cannot use the Router of plug or phoenix for the routing in this case. You need to create a wildcard route, which simply matches any url that finds it’s way to your endpoint and use custom plug to implement the routing to controllers or whatever needs to receive the request if the url is valid. The routers of plug and phoenix are based on compiled pattern matching functions, so they cannot be dynamic (or even support regex).
MisterD
Thank you for reply.
I understand that I cannot use that as I already tried without success.
I would prefer not to create a wildcard route due to performance issues.
The question is - how to achieve the desired behaviour without losing performance.
idi527
There wouldn’t be any performance issues if done correctly. I have a plug for webhooks that are generated at runtime to which I
forwardfrom the phoenix router module.It works roughly like this
LostKobrakai
Do you have performance issues? If not I’d not worry to much until you have. If you do then what have you tried?
MisterD
No, I don’t currently have that.
I just remember there was a post by Chris McCord stating that using a wildcard route would lead to performance problems.
MisterD
Thank you very much for your example, I really appreciate it !
Probably this is something I should use for now, and if there would be any issues, then look for something else.
One more time, thank you everyone for help !
easco
A Plug accepts a
Plug.Connand returns a differentPlug.Connresource.Part of the
Plug.Connstructure is the “path_info”. Your plug could look at the Path Info and decide what function to call, pass he connection to it, andhaltthe propagation of the connection (so the the router never sees it).Or, it could return a new
Plug.Conn, with differentpath_info, let it propagate to the router, and the router could use its regular mechanism on the new path_info.