Friday, May 20, 2011

nginx include(s)

As part of my ongoing exploration with dotcloud, I've had to do a bit of learning about nginx.

I've never worked with nginx before but i needed to add some rewrite rules into my dotcloud deployment. I wanted to make sure that static content like images and css files where being served by the nginx instead of my app (Dancer is pretty nice about making sure public content gets served during requests).

I found that after changing a nginx include that the server needs to be restarted or reloaded after a change to the include. I spent a few hours trying to figure out if a restart was required since I wasn't sure if I had screwed up the rules due to a bug (now fixed) with dotcloud deployment not restarting it after a push as expected for Perl deployments.

dotcloud provides server restart as: udo /etc/init.d/nginx restart

__END__

Wednesday, May 18, 2011

My First Custom Dancer app deployment on dotcloud

I'm in the process of rewriting my site www.leecarmichael.com. I really wanted a reason to build a small but real app with (Perl)Dancer.

I really like most of Dancer's approach to routing and layout. It fits well with my way of thinking of web apps. At the same time I stumbled onto Dot Cloud, a very well thought out and incredible nice deployment provider. They are part of the current cloud shift in which individual application stack layers are hosted instead of a full OS stack.

Here are the few gotchas that I found:
  • They deploy using PSGI and Plack, very cool. But its deployed with an environment of 'deployment'. This means you must have a deployment configuration file. Example: application_root/environments/deployment.yml. I found this confusing since i expected it to follow the Dancer approach of production (my own bad assumption)
  • Unfortunately, runtime errors are not logged to the standard web server error log (or anywhere else). Therefore you need to turn on core logging to find serious errors. I did this by adding the following to my config: debug:"core". ( I am opening a bug :)
  • Lastly I needed to add DBD::mysql to my Makefile.PL (which is really a great way to handle dependancies for deployment). I overlooked this since it was hidden in my app since its not directly 'use'd. (so much for being smart with: ack use --perl :)

Next on my list is to use the Aliases feature to completely move the site and I need to figure out how to exclude subversion meta files from dotcloud push. But first I need to work on the editing part...

Then comes:
  • Custom 400/500 pages
  • Changing header images
  • other fun stuff

__END__

Friday, May 13, 2011

Using Dancer's Request HTTP Env shortcuts

As I was working on a small application that allowed editing of pages, I really wanted to grab the referring page to redirect after the page was updated or the edit session was cancelled by the user.

It wasn't very clear to me how to grab the referer from Dancer's POD documentation on Dancer::Request.

Basically I could grab it either of 2 ways.
  1. request->referer - nice. This applies to other env options as well forwarded_for_address which pulls in X_FORWARDED_FOR
  2. request->env->{HTTP_REFERER} - feels more lower level.
I read the documentation as request->env->{referer} which is not correct at all.

In the end it is much easier and I think prettier than the several options I tried :)

__END__

Thursday, May 5, 2011

Dancer and TT config

Quick note to self (and anyone that might be listening): When setting config options different than start and end tag for TT such as PRE_PROCESS in Dancer, you must make them all caps.

e.g. config.yaml:
# template engine
template: "template_toolkit"
engines:
   template_toolkit:
     encoding:  'utf8'
     start_tag: '[%'
     end_tag:   '%]'
     PRE_PROCESS: 'config.tt'