Heroku DNS: point subdomain to folder (Rails) - heroku

I have a subfolder (domain.com/folder) and I'd like to create an Alias (CNAME) for it of folder.domain.com. However, I seem to be unable to find the relevant documentation.
Any hints or suggestions?
Thanks,
Nick.
EDIT
constraints :subdomain => "connect" do
scope :module => "connect" do
# all the stuff i want to be in the subdomain
end
end
Getting uninitialized constant Connect using http://connect.lvh.me:3000/apps and No route matches [GET] "/apps" for http://connect.localhost:3000/apps
What's going on here?

Related

laravel in subdirectory but route points to parent directory

i have a problem in laravel route i don't know how to fix it!
well first of all i should say my webserver is lighttpd and there's no way to change it to nginx or apache if you want to say use another webserver... :D
well, my project was in "/path/to/some-where/htdocs" and my domain was "example.com"
and in "lighttpd.conf" i pointed "example.com" to "/path/to/some-where/htdocs/public/" and everything worked well and laravel worked fine, but because of some reasons i made some changes cause we needed "example.com" domain for some other projects
i moved project to "foo" subdirectory so now my project path is "/path/to/some-where/htdocs/foo/" and also i made some changes in lighttpd and pointed "example.com/foo" to "/path/to/some-where/htdocs/foo/public/"
also i changed APP_URI in .env to "http://example.com/foo"
but when i open "example.com/foo" it shows me "route not found" error, laravel it's working but it doesn't recognize "/foo" as base directory and when i put all of routes in a route group with "foo" prefix it works fine!
for testing i made these routes
Route::get("/", function(}{return "sweet home!";));
Route::get("/{slug}", function($slug}{return $slug;));
when i open "example.com/foo" it should show me "sweet home" but instead, it shows me "foo" cause as i said laravel doesn't recognize "foo" as base directory
it seems i should change base directory or base uri of project but i couldn't find anything
as i said i changed APP_URI, and also i put
RewriteBase /foo/
in .htacess but no result!
You should prefix your routes this way :
Route::group(['prefix' => 'foo'], function() {
Route::get("/", function(}{return "sweet home!";));
Route::get("/{slug}", function($slug}{return $slug;));
});

Jekyll site via Sinatra and Heroku - can't route to new posts

I created a 'Hello, World' app using Sinatra and then pushed to Heroku and all worked.
I've since created a basic Jekyll blog, and am trying to access it via Heroku using the following routes:
get '/?' do
file.read("_site/index.html")
end
get '/.*.*' do
file.read("_site/#{params[:splat]}")
end
not_found do
file.read("_site/error/index.html")
end
The route to the index works fine link to my site
but as soon as I click to the first post it always fails.
I have tried so many variations of different routes for the :splat and get, just can't seem to get it to work? Any ideas?
In the route that's failing, before the file.read statement, add warn "splat = #{params[:splat]}" and that will output the result to the terminal, and you can see what it's actually getting, e.g.
get '/.*.*' do
warn "splat = #{params[:splat]}"
file.read("_site/#{params[:splat]}")
end
You could also try using an absolute path to the files, though if you're getting the index page then it suggests it's not needed:
config do
set :statics, File.expand_path(File.join(settings.root, "_site"))
end
get '/.*.*' do
file.read( File.join settings.statics, params[:splat] )
end
Unless there's something else you were planning to use Sinatra's routes for, you could probably remove the Sinatra routes entirely and just make the "_site" folder the public_folder, and then Sinatra will do the serving of the static files for you:
config do
set :public_folder, File.expand_path(File.join(settings.root, "_site"))
end
# no more to do...

Devise not working well with multiple subdomains on RoR3 application

I have seen a lot of questions about this topic, but a lot of them have contradictory information, and for some reason it didnt work for me.
I have:
a top level domain: i.e. lvh.me (development).
each user has subdomains: i.e. userdomain.lvh.me
The login form is in the top level domain: lvh.me
I want:
If an user logs in, the session needs to be shared between all the subdomains. I mean, the session needs to be active in lvh.me:3000/something and userdomain.lvh.me:3000
If an user logs out from lvh.me:3000/something it should work, and if the user logs out from userdomain.lvh.me:3000 it should work also.
I tried
Setting in an initializer the following:
MyApplication::Application.config.session_store :cookie_store, :key => '_mykey', :domain => :all
What happened?
I can login in lvh.me:3000, I am correctly redirected to lvh.me:3000/internalpage and if I go to subdomain.lvh.me:3000 it works great. I can also logout from lvh.me:3000/internalpage BUT if I try to logout from subdomain.lvh.me:3000 it doesn't work. The destroy action in Devise SessionsController is executed and everything, but the session doesn't die.
According to http://excid3.com/blog/sharing-a-devise-user-session-across-subdomains-with-rails-3/,
The trick here is the :domain option. What this does is sets the level
of the TLD (top level domain) and tells Rails how long the domain is.
The part you want to watch out for here is that if you set :domain =>
:all like is recommend in some places, it simply won’t work unless
you’re using localhost. :all defaults to a TLD length of 1, which
means if you’re testing with Pow (myapp.dev) it won’t work either
because that is a TLD of length 2.
So, after reading that I also tried
MyApplication::Application.config.session_store :cookie_store, :key => '_mykey', :domain => 'lvh.me'
What happened?
I can login in lvh.me:3000, I am correctly redirected to lvh.me:3000/internalpage and if I go to subdomain.lvh.me:3000 it doesn't work, i have no session there. If I go back to lvh.me:3000/internalpage my session has disappeared. What happened there?
What else?
Then, after reading rails 3.2 subdomains and devise I changed my initializer line to
MyApplication::Application.config.session_store :cookie_store, :key => '_mykey', :domain => '.lvh.me'
Note the "." before the domain name.
According to the post in SO:
This allows this cookie to be accessible across subdomains and the
application should maintain it's session across subdomains. May not be
100% what you are looking for but it should get you going in the right
direction.
What happened?
Nothing, it didn't work. Same behavior if compared with the last thing I tried.
I finally tried What does Rails 3 session_store domain :all really do? , creating a custom class to handle the cookies. But I had no luck.
Of course that I deleted all the cookies and temp files before each attempt. Also I changed the name of the cookie.
Any help? Thanks!
According to this guy here: Rails: how can I share permanent cookies across multiple subdomains? You need to set the domain manually? Googling around it looks like '.domainname.com' with the dot at the beginning really is the way to go.
If you inherit from Devise::SessionsController you can manually set it on create
class SessionsController < Devise::SessionsController
def create
# modify the cookie here
super
end
end
I am setting up a working example to test that out, I'll post back afterwards, cheers!
And here is my Edit
Forget tempering with the token on create. The problematic is this, you need to have the token domain set to '.lvh.me' that's all there is to it, but domain: '.lvh.me' just doesn't do anything. Here is my proof of concept and ultimately it boiled down to a single change inside a controller:
class HomeController < ApplicationController
def index
cookies[:_cookietest_session] = {domain: '.lvh.me'}
end
end
In Chrome the token would look like this
And that for subdomain.lvh.me, lvh.me and any other subdomain I tried. I can sign_in/sign_out from any and the session is created/destroyed accordingly.
Now I wouldn't advise doing it the way I did, I liked the middleware approach I think it would work just fine if setup properly. Let me know if you need further help on this.
Cheers!
Ok last thing
I went back and tried domain: :all because it really ought to work as you have expected. If I access lvh.me I get a cookie with .lvh.me but if I got to subdomain.lvh.me I get one that reads .subdomain.lvh.me
I think the issue is that :all adds a . to the subdomain.lvh.me so you would stay logged in with foo.subdomain.lvh.me which doesn't do you much good.
:all seems to work if your original login is from the root domain lvh.me and you then redirect to a subdomain. but you can't log in through a subdomain with it set that way.
MyApplication::Application.config.session_store :cookie_store, :key => '_mykey', :domain => '.lvh.me'
looks like the correct way to specify this.
Note:
Make sure you restart rails after making change.
Make sure you clear cookies out for your domain before testing again. You can leave remnant cookies behind that are confusing between tests.

ActionController::RoutingError (uninitialized constant User::UsersController) in heroku (but everything works in local)

I am trying to run my app in heroku but I get this error when trying to signup or even access devise's login page:
ActionController::RoutingError (uninitialized constant User::UsersController)
Is this a devise bug or a server setting i missed in heroku?
I am running a rails3.1 app in a cedar stack by the way and loading the index page is good, but if I try to login or sign up, it blows.
The signup form DOES show, but when I submit, that's when it blows. I checked the logs and it did POST to the controller but GETting the resulting page(when redirected I guess) blows it up.
Any help?
EDIT
here are my routes:
root :to => "home#index"
devise_for :users
namespace :user do
root :to => "users#welcome"
end
resources :users, :only => :show
A heroku support person also asked about my routes but why does it happen in production only? Also I don't think there's any problem with the routes...is there?
I found the you do not need to remove the default root for when a user logs in. So replace the namespace call and use the following:
match 'users' => 'users#welcome', :as => 'user_root'
This way you can still have two "home" pages. It worked for me.
https://github.com/plataformatec/devise/wiki/How-To%3a-Redirect-to-a-specific-page-on-successful-sign-in
This is your problem:
namespace :user do
root :to => "users#welcome"
end
Can you remove this?
I got the same error. Error was only reproducible in Heroku, not locally. What I realized is that while I had added the resource to routes and pushed that, all the generated scaffold was still lying locally. Once I added all the generated stuff to git and pushed, worked fine on Heroku.

How can we get multi_site extension for Radiant working on Heroku?

Has anyone got RadiantCMS with multi_site working on Heroku? I actually tried it and it bombed big-time giving the error:
Heroku | No such app
There is no app configured at that hostname.
Perhaps the app owner has renamed it, or you mistyped the URL.
This is what I tried:
Go to tractor.heroku.com and login using admin / radiant.
If you see the 'Sites' section, you will find Foo and Bar sites.
I edited my /etc/hosts files and added foo.myapp.com and bar.myapp.com to the IP address that resolves to tractor.heroku.com (Not entirely sure if this is right)
Now type the URL "http://foo.myapp.com" in the browser and it gives me the above error.
Is there some special configuration required to get this working on Heroku?
So, I finally did get an answer from heroku support themselves. Pasting it here for everyone's benefit:
reception said:
fyi if you want a 301 redirect from appname.heroku.com url to yourdomain.tld i succeeded with this steps:
freeze radiant (in order to be able to modify application_controller.rb; see http://wiki.github.com/radiant/radiant/running-on-edge )
add this code to application_controller.rb inside class ApplicationController:
---->8
before_filter :redirect_domain
def redirect_domain
if request.host == 'appname.heroku.com'
redirect_to "http://yourdomain.tld#{request.request_uri}", :status=>301
end
end
---->8
(big thanx to David from suppport!)
regards
D

Resources