How to mask my landing page when user not signed in? - ruby-on-rails

I got my web platform built on ruby on rails at https://example.com
My landing and about pages are hosted in a Wordpress in other host at https://examplecms.com.
What i would like to achieve is to make users to visit https://example.com get masked https://examplecms.com except when they are logged in as my platform's dashboard is routed in the root path /.
What i am trying to avoid is the user to see in the URL https://examplecms.com.
I've tried so far a couple of tricks:
In my home/index action controller i've redirected to https://examplecms.com if the user is not signed in. But this fails as it still shows the CMS url in the user's browser.
Using an Iframe in the render of the home/index view pointing to the CMS site. It works because it stills present my site URL correctly but this seems kind of fishy also deep linking and navigating does not seem to work correctly.
I have been thinking into doing at proxy server level, using .htaccess or even using DNS strategies but i can't come up for a solution to these strategies to detect when the user is signed in or not?
Any ideas?
Thanks
Update:
Stack:
Ubuntu
Ruby on Rails
Nginx + passenger
Amazon Ec2 + Cloudflare DNS

You can use http://nginx.org/r/proxy_pass to silently redirect the user to a different page, without changing the URL that's shown to the user within the Location field of the browser.
To check whether the user is logged in, you can install an error handler via http://nginx.org/r/error_page to redirect the user only if your normal page returns an error (e.g., if the normal proxy_pass results in a 403 Forbidden response, then redirect the user's request to the alternative proxy_pass upstream as per the error handler).

What you're looking for is route scopes. I'm using Devise for authentication, which provides helpers for doing what you want, but I have no doubt you can adjust for your needs. When a user hits any page on the site, they are automatically redirected to the login. If they are logged in, they are redirected to the homepage/URL they typed in.
authenticated :user do
root to: 'titles#index'
end
devise_scope :user do
root to: 'devise/sessions#new'
end

Create a subdomain
For your WordPress hosted web content, you could create a very simple subdomain on your hosting provider like so
blog.example.com that is alias to examplecms.com
Use Device Gem for Authentication
You can use the device gem to authenticate the user and route the user to the subdomain. When the user hits the /root_path.

Related

Struggling with setting up correct redirection on AWS application load balancer.`

Wondering if someone can help me understand this peculiar behaviour I am seeing with the AWS ALB redirects.
We have a web application running on EC2 instance which shows three different types of login pages when the correct context path is used like below which works fine:
https:///ucmdb-browser (redirects to the default application login page)
https:///console (redirects to the administration login)
https:///status (redirects to the applicaiton status page)
and
https://<internal-ec2-fqdn/ (Page not found)
So all working as expected.
This Web application is now fronted with AWS ALB so it can be accessed from outside world.
where if someone types:
https://<externalalb-fqdn/ (should redirect to /ucmdb-browser and show the login page)
https://<externalalb-fqdn/ucmdb-browser (should redirect to /ucmdb-browser and show the login page)
https://<externalalb-fqdn/status (should redirect to /status page)
https://<externalalb-fqdn/console (should redirect to admin login page)
https://<externalalb-fqdn/ (should redirect to custom 404 error)
To do this, my settings in AWS listener looks like below:
enter image description here
Now the issue is, whenever I type, any of the URLs, it is being forwarded to 404 page only and unless I change the last default action rule to the actual UCMDB target group.
But that defeats the purpose because one could type any context path whatsoever and it still transfer the request to the application server.
Not sure what wrong I am doing but I have tried all the various combinations I can think of.
Any help is appreciated.

How do I set up a Rails page as a subdomain of another site?

We're trying to create pages in our Rails app that will eventually live on a subdomain of another partnering site. This would be like StatusPage, which allows users to create a status page with their account on the StatusPage site and then attach it to their own subdomain (e.g. status.usersite.com).
For example, if we wanted one of our pages (www.oursite.com/users/bobsplumbing) to be a subdomain on another site (ourservice.bobsplumbing.com), how would we go about it?
If it's useful info, we use Heroku to host the Rails app and we also utilize Route 53 and Cloudflare.
From your example I understand that you want to have multiple web apps since that would be your customer domain and your page will redirect to that page.
You will be better off to do NGINX (or whatever you use) redirects since they are faster and will take less time, being cached by the browser after the initial load.
To answer your question you can add this code to your routes:
sites = %w(bobsplumbing catsandboots)
sites.each do |name|
match "users/#{name}" => redirect("https://ourservice.#{name}.com")
end
You can also have a look at apartment gem.

Rails routing to subdomain

We have a site at www.example.com but needs to move it to subdomain1.example.com, while maintaining the SEO links. We are planning to use Google's Change of Address but it requires 301 redirects.
We plan to release another site at the www.example.com address.
Is there a way to changes the routes.rb of www.example.com so that certain routes gets redirected to subdomain1 and others don't?
I am not sure exactly what you mean by redirect but here are some options:
You can redirect a route to another route in your rails app using:
get '/some_route', to: redirect('/other_route')
Or if the subdomain is a seperate app / service you can redirect in a controller using:
redirect_to "http://www.rubyonrails.org"

Groovy/GSP redirect around controller

I have a web application that I am trying not to recompile since there is little documentation and the environment is a little sensitive.
With that in mind, all I am trying to do is hijack the authentication mechanism to redirect to one of a couple replacement websites. To that end, there is an authentication service and an authentication controller. The website redirects to /auth/login when the user comes unauthenticated.
In the views folder I have built an alternative /auth/login_new.gsp and from there can authenticate the user and get a redirection back to /auth/redirect.gsp at some frequency but not 100%. That redirect page takes a value from the DB and redirects the user to the correct follow on website. When I run authentication from /auth/login, the site ignores the redirect request to /auth/redirect.gsp.
I had set the show pages for all the different controllers to window.location.href="/auth/redirect.gsp" but I can't get it to go there 100%. I have also reset the layout/domain.gsp file to gut the other functionality of the site and script redirect as well. I was getting errors with duplicate redirect attempts, but now I just go to a dead/gutted homepage...
Any suggestions on how I can dodge the recompile?
Thanks
Leif

Rails on Subdomain and Custom Port

I have to run rails on a shared host for a client via cPanel.
The application is running on a subdomain and non standard port.
I am using Authlogic, so on the first visit it detects I am not logged in and I get a page with:
You are being redirected.
Clicking on that I get the login form, which then takes me to the target page, with the same redirect message. So the model detects the login, but no cookie or session is ever created.
I have tried the following with no success:
config.action_controller.session = {:domain => '.bbbb.com'}
I've also tried using an active record session with same result.
Please help :)
Thanks
Are you using, or have you looked at SubDomainFu?
http://github.com/mbleigh/subdomain-fu

Resources