dogweather

dogweather

Using Phoenix as a "redirect server". Anyone else?

This has been a super-useful app for me and Phoenix is ridic fast and efficient with memory. Here’s the gist of it. There are a lot more entries in the actual app:

In router.ex:

    get("/oregon_revised_statutes", RedirectController, :ors_statutes)
    get("/ors/volume/:number",      RedirectController, :ors_volume)

And in redirect_controller.ex:

  def ors_statutes(conn, _), do: perm_redirect(conn, to: "#{@opl_url}/statutes")

  def ors_volume(conn, %{"number" => number}) do
    perm_redirect(conn, to: "#{@opl_url}/statutes/ors_volume_#{number}")
  end

I’ve got all my old deprecated domain names pointed at this app, and it redirects to the new servers. Architecture-wise, it’s been a success: Usually, these legacy redirects would be in my actual app (unrelated code), or in a service like Cloudflare (good, but gets expensive.) The separate redirect server keeps these legacy business concerns (reallly SEO concerns) out of my production business app. And it will run on the cheapest Gigalixir instance.

I’m not a huge Phoenix expert. Anybody doing this a different way?

Most Liked

dimitarvp

dimitarvp

These days I’d reach for nginx or caddy but admittedly the approach chosen by OP is more programmable and likely a little bit more manageable.

fuelen

fuelen

Yes, I’d write a helper which allows to do the job in router

redirect("/oregon_revised_statutes", to: "/statuses")
redirect("/ors/volume/:number", to: "/statutes/ors_volume_:number")

and maybe use a different file which defines these routes. Another service is overkill IMO.

EDIT: ah, I see, domain name had been changed as well. Then another service is OK :slight_smile:

AstonJ

AstonJ

Nice! Haven’t used it in a long time but I’ve used (Apache) mod_rewrite for redirects in the past - I’d be curious to know it performs compared to your Phoenix app :smiley:

Where Next?

Popular in Discussions Top

hazardfn
I suppose this question is effectively hackney vs. ibrowse but we are at a point in our project where we have to make a choice between th...
New
sergio
There’s a new TIOBE index report that came out that shows Elixir is still not in the top 50 used languages. It also goes on to call Elix...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
jer
I’ve been using umbrellas for a while, and generally started off (on greenfield projects at least) by isolating subapps based on clearly ...
New
vans163
So useless benchmarks aside, Its possible to write a webserver that can serve 300k requests per second (perhaps more with optimizations)....
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 13924 124
New
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
mmmrrr
Just saw that dhh announced https://hotwire.dev/ Is it just me or is this essentially live view? :smiley: Although I like the “iFrame-e...
New

Other popular topics Top

johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

We're in Beta

About us Mission Statement