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:

Last Post!

AstonJ

AstonJ

Yeah I’d agree - I hated having to write rewrite rules using mod_rewrite :lol:

Could be a great selling point if the Phoenix app performs just as well :003:

Where Next?

Popular in Discussions Top

ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
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
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement