poteto / terraform

A simple plug for incrementally transforming an API into Phoenix. Check out the blog post:

Home Page:https://www.no.lol/2016-08-12-rise-from-the-ashes-incremental-apis-with-phoenix/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proxy from within controller action

tfwright opened this issue · comments

Hi, great library, it has made migrating my legacy rails app to Phoenix a breeze.

Recently I had an endpoint I needed to migrate that has drastically different behavior depending on request params. Not an ideal design, but since I'm dealing with some pretty complex legacy code, I really wanted to migrate only one implementation at a time. However, since Phoenix doesn't support matching routes based on query parameters (AFAIK), I couldn't rely on terraform's default behavior. What I ended up doing was using pattern matching and manually calling the plug, which seemed to work great, but I did run into an issue where since the raw body had already been read and discarded, they weren't getting sent along to the Rails app. So I just wrote another simple plug to cache the original body and check for that in my terraform plug.

So my question is, would it make sense to build in an official way to handle this within terraform? I would be happy to contribute the code I already wrote and/or open a PR.