Our company started out with a single product, a rails app backed by some java services, then decided they wanted another product that was initially considerably different than the first, but as time has gone on we've realized they are starting to converge, and making a code change to one requires a similar code change to the other for a new feature/bug fix. This is obviously becoming a pain.
In some cases we have gems that share some of this functionality but it goes beyond ruby into javascript, css etc..
So I'm tasked with merging these two apps into one codebase. I think eventually we'd like it to be a single app with permission based role access but that will come much later.
My first thought to quickly put them together is to create two rails engines and share common libs between them. I think this is the quickest way to combine the code, find common sections and start sharing.
My first problem though is how to route between the apps. One app uses a single domain name that never changes, the other app has many domains. Can someone suggest how I might route a particular request to a particular app so they can remain separate to start whilst sharing a common codebase of libs?
Or, if anyone has other suggestions as to a way to combine these apps I'm all ears.
They're both Rails 2.3.10 apps running JRUBY 1.5.3, but we're open to possibly upgrading to Rails3 if that would make things significantly easier or cleaner (ie with better Rack integration)
I haven't done any Rack programming but never hurts to learn if that will make our lives easier.
You should avoid sharing code on server level, best to do that would be building libraries including common code base and use them during development. Probably the best shoot would be using helpers as it is easiest way to provide modules that provide functionalities all over your code.
Regarding rewriting functionalities to one application, choose that one with bigger set of ready code as a base. It should be possible to migrate code per method using web server supporting url rewriting. I thought of using apache with mod_rewrite. So the plan would be:
You do not have to use apache, there should be other web servers supporting url rewriting.
I was thinking of using this algorithm to rewrite our application to rails 3.0.
Your idea of using engines is what I would suggest.
For routing, I would handle it outside of Rails.
For instance, you would do the following in nginx:
server {
# Match only one host.
listen 80 default;
server_name YOUR_SINGLE_APP_DOMAIN;
location / {
upstream YOUR_SINGLE_APP_RAILS;
}
}
server {
# Fall thru and match any other host.
listen 80 default;
server_name ~^.*$;
location / {
upstream YOUR_MULTI_DOMAIN_APP_RAILS;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With