Rails Router Override

This is strange, I know. I am trying to link two Rails applications, v3 and v2.3.5

I want them to share the same domain, and for this, without changing the URLs in the older application, I am trying to find a way to redefine the Rails router.

I want the new application to be in the root of the domain, and the older one in several directories. For instance:

/          => app1 # v3
/users     => app1
/employees => app2 # v2.3.5
/payrolls  => app2

So, since app1 lives in root and I use Passenger, I need to create symbolic links in the publicapp1 folder for the app2 shared folder, for example:

app1/public/employees => app2/public
app1/public/payrolls  => app2/public

Then add RailsBaseURI /employeesand RailsBaseURI /payrollsin Apache configuration.

URL- app2, . , /employees/1, /employees/employees/1, /payrolls/employees/1 , /employees/employees/1 /payrolls/employees/1 , .

, , URL.

, . v3 , , .

, , Rails , , , , .

+3
2

, url_for ApplicationHelper :

def url_for(options = {})
  original = super(options)
  # I tried this in order to improve performance:
  return original unless original.starts_with?('/employees/employees')
  original.gsub('/employees/employees', '/employees')
end

, . , - .

, .

+1

, , - haproxy .

# In haproxy.conf:

  frontend rails
    bind *:80
    acl rails2 hdr_host(end) -i employees.mydomain.com
    acl rails3 hdr_host(end) -i mydomain.com
    use_backend rails2_server if rails2
    use_backend rails3_server if rails3
    default_backend rails3_server

  backend rails2_server
    server myrails2_server 192.168.1.1:3000 check

  backend rails3_server
    server myrails3_server 192.168.1.1:3001 check

DNS- mydomain.com haproxy IP employee.mydomain.com mydomain.com/employees.

, IP- haproxy- mydomain.com /etc/hosts

0

Source: https://habr.com/ru/post/1792276/


All Articles