How to host different applications without subdomains in Heroku? - ruby-on-rails

I would like to have different applications under the same domain using Heroku.
Because of the name of the domain, I would like to access the applications using folders (mydomain.com/app) instead of using subdomains (app.mydomain.com), is this possible? Thanks

There is no type of URL re-writing you have access over thats going to do that for you. You could create a "stub" Siantra-based app that allows you to define those types of URLs, but it would have to effectively redirect you to the subdomain version.
I'd have to play devil's advocate and ask why you'd want to have things namespaced as /app instead of using subdomains. Subdomains offer much more flexibility and are a lot less brittle than essentially having to url-rewrite all the time based on the first "slash" element.

You can't do this with heroku - it assumes the directory structure of the Rails application.

Related

redirect a subfolder from heroku to dedicated WordPress hosting

I have a simple site on heroku using Harp (not married to harp, just used something that can serve up static HTML.
We need to add a blog in a subfolder domain.com/blog instead of blog.domain.com for SEO reasons. Is there a way on Heroku to redirect just a subfolder?
I don't want to host, manage or deal with WordPress in any fashion. I'd like to avoid running any other blogging software. My preference is just to leverage the hosting solutions without losing SEO scores.
You'd have to do the redirect in Harp, but unfortunately Harp doesn't support server-side redirects. You can do a client-side redirect, though.

Set up custom domains for users using rails 4, nginx with passenger

I have a rails application that uses subdomains to allow users to have their own seperate data in a CMS system. Basically a SaaS CMS system like wordpress.com or tumblr.com.
However i would like to give users the ability to choose their own domain (av alias for their subdomain). For example the user henrik.cmsdomain.com would like to have a custom domain that reads henrikswebsite.com.
How can i do this? Do i need to set up my own name servers? I'm not necessarily looking for complete answers, i just don't know where to start.
Im running on an ubuntu 13.10 digitalocean server with nginx, passenger, Rails 4 and postgresql (using schemas to seperate userdata).
What you're looking for is something called "virtual subdomains" (I think). Here is some information about how to set them up:
http://signalvnoise.com/posts/1512-how-to-do-basecamp-style-subdomains-in-rails
Rails Restful Routing and Subdomains
You basically need to set up a "wildcard" subdomain in your DNS (which will route all subdomain requests to your app), and let the routing middleware handle the request (& route accordingly)
Domains
Considering the updates, I have had a look online for you:
Rails routing to handle multiple domains on single application
I don't have experience of this directly, but I'd say you first need to get the domain to point to your site (with CNAME changes). This could then be caught by your routing middleware (as described in the link above), allowing you to "route" the request accordingly
Heroku does this exact thing - it's quite common

Have a subdirectory in an external domain point to a rails app without URL change

I have a rails app hosted on Heroku at, say, app.herokuapp.com
I would like to know if there is a way to have an URL such as www.external.com/app that points to my rails app but does not redirect. Just masks the URL and nobody ever knows that the app is really hosted at another domain, different from external.com.
Though about an iframe, but it is not a very nice solution.
I think this depends on what server you are using. If you are using Apache, then you might want to take a look at Domain forwarding in Apache.

Rails/Heroku RESTful locale best practice?

What do you consider the best practice to handle locales and internationalization in a Rails app on Heroku in a RESTful way? What is your bit of code that gateways the user according to their locale? Is a subdomain solution (http://de.myapp.com, http://en.myapp.com, …) possible without the wildcard subdomain add-on on Heroku?
I don't believe there is anything to stop you using http://de.myapp.com, http://en.myapp.com and friends on Heroku.
Rather than using wildcard domains, what you'd have to do is:
Manually configure your DNS domain to provide 'true' DNS names for each locale.
Add each domain manually using the (free) Custom Domain plugin.
Obviously this is a bit more work than using wildcard domains, but should be fine unless you've got a lot of locales to manage.
You have different options to set the locale, e.g. you could as well go with myapp.com/en/... .
See RailsGuides for more information. There is no need to mess with domains unless you absolutely want to :)

Architecture: worker/director (3 main roles) in one same rails app

I want to develop a rails app that does this:
a public front-end deployed on some place like Heroku
a private front-end that I can access (this would be someplace like my home/office where it is the only app running)
a private backend that collects and analyses data (the public front end can access the backend through an API,this would be someplace like my home/office where it is the only app running)
I want to keep the code base the same so I was thinking of modifying environment variables accordingly.
So, two things:
is this a good architecture for this?
how would I run a back ground worker thread/process on the private front/backend machine
thanks
This is one application.
My suggestion is that you use an authentication framework, my suggestion would be devise (https://github.com/plataformatec/devise) and an authorization framework like acl9 (https://github.com/be9/acl9) or cancan (https://github.com/ryanb/cancan).
The fact is smarter people than you and I have built fantastic frameworks to solve just this problem and there's no point reinventing the wheel when something already exists. Plus, writing authentications systems might seem easy but it's actually incredibly complicated.
I would also not recommend restful-authentication or acts_as_authenticated, especially if you're building a rails 3 application.
If you're planning on deploying on heroku using environment variables isn't going to work because:
The variables will be the same across all of your dynos.
If you want to run different apps you need to go for their new database offerings which are quite expensive.
Consolidate everything into one app, your life will be easier in the long run!
For background workers you can use resque and dynamically spin up workers (http://blog.darkhax.com/2010/07/30/auto-scale-your-resque-workers-on-heroku). Use different queues if you want for the public/private facing stuff if they have different SLAs.
I hope this helps, if you have any more questions leave a comment.
What about authorization? I'm using this plugin with Restful authentication for authentication.
With it I define roles and where it can access, and give a role to each user. The user log in and the controller (or the view) checks the user's permissions and respond properly (you'll need to code a bit, but it's the most elegant and safer way, I think).
You could perhaps use authentication to figure out who is accessing things, within the controller.
Couldn't you use a before_filter that authenticated access and authorised different levels of functionality, based on authenticated user?
For authentication, you could go for something simple like this (cheatsheet here):
http://cheat.errtheblog.com/s/acts_as_authenticated/
or a better one:
https://github.com/technoweenie/restful-authentication

Resources