Normally the way I do my sites, I have a "dev" site and then the "production" site. This takes the form of:
http://d.foo.com/ (Dev)
http://foo.com/
I usually secure the dev site to only allow me access, I do this through Basic auth... in MVC it's hard to say, "restrict everything except the account controller," or at least I haven't found an easy way to do it, that's why I like the catch all authorization at the IIS level.
Can I do anything similar with AppHarbor? I definitely like the workflow but I also like to test my apps before I deploy them for all to see.
The only way I could do it right now (I think) is creating a new application, associating it with the relevant sub-domain (d.*), and adding that as an extra remote push. But I would then need some way of figuring out I am in dev and securing the site.
#1 Posted by friism Support staff on 06 Apr, 2011 01:50 AM
There's an open request for this feature.
In the meantime, using two AppHarbor applications is probably a good idea. You can discriminate between by development and production checking the host-header. You could also use AppHarbor AppSettings configuration-variable-replacement. You can configure these in the application interface.
You could add an attribute to your controllers that determines whether requests are for the development site and require basic http auth if that is the case.
Let us know if this works for you.
#2 Posted by subkamran on 06 Apr, 2011 04:19 AM
Thanks, this approach seems to work albeit it does require some extra plumbing:
git remote add appharbor-d {your dev url}Create a new derived Authorize attribute and attach it to your
BaseControlleror a controller you'd like to be protected in dev:Change it according to your needs. I might refactor into an Enum. In my main app, I set the variable to "P" to denote production... but I don't use it yet.
To push to dev:
git push appharbor-d masterand to prod:git push appharbor master.I also added a line to skip authorization for the Account controller. This was important for me because otherwise my OpenID redirection didn't work (it still has an issue with the port numbers but that's for a different discussion).
Hope this helps other people. I'd love to this baked into AppHarbor so I don't need to require code but this works and is fairly lightweight.
#3 Posted by subkamran on 06 Apr, 2011 04:26 AM
PS.
ToSafeString()is a simple extension:return value == null ? String.Empty : value.ToString().Use the attribute like:
#4 Posted by friism Support staff on 06 Apr, 2011 03:56 PM
Cool, thanks for sharing. Is this something you would be interested in writing up for a blog post, either for your own blog or as a guest post on the AppHarbor blog?
#5 Posted by subkamran on 06 Apr, 2011 04:14 PM
I just made one:
http://kamranicus.com/Blog/Posts/2/befriending-appharbor-and-making...
Hope that helps some people out!
#6 Posted by friism Support staff on 06 Apr, 2011 04:37 PM
Perfect!, thanks.
friism closed this discussion on 06 Apr, 2011 04:37 PM.