Partial migration from Rails to Phoenix

Viewed 248

I have a rails app, and I want to gradually move it to Phoenix. While I implement functionality I want phoenix intercept the requests that are already implemented while passing unknown requests down to Rails app. What would be the best strategy in this case?

1) If I'm ready to accept some overhead, I could create a plug and route all unknown requests there (last route /*path). But how do I pass request intact and return the response? Parse it and then build again with HTTPoison would by unnecessary work, any better ideas?

2) I'm not sure, if it's possible with haproxy, but old app could be a fallback, where request would be passed if main backend responds with some error. Would this introduce less overhead?

3) Finally I could just split requests by mask in haproxy, but it seems like to much work, cause I'm planning on using rails for CUD actions and phoenix for R for some resources.

Any other options? Examples how someone done that? Thank you!

1 Answers

Read an excellent post about your exact problem here . The basic idea is to use a gem rails-reverse-proxy to define a proxy to your Phoenix application.

Then, develop your feature on Phoenix, and add the necessary routes. Keep the rails conventions(it's the way the phoenix router works anyway).

Wire your rails app with a 'dummy' controller and set it to use rails-reverse-proxy.

It is recommended that you make all the ActiveRecord models that are owned by the Phoenix app read only. By adding a hook after_initialize :readonly! to the models owned by pheonix. This way you can use the models in Rails without compromising the phoenix ownership. Only the Phoenix app can change the model state.

Related