Skip to content

Instantly share code, notes, and snippets.

@zorbash
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save zorbash/9125554 to your computer and use it in GitHub Desktop.

Select an option

Save zorbash/9125554 to your computer and use it in GitHub Desktop.
nginx + mruby experiment, /songs/random endpoint.
server {
location /songs/random {
mruby_content_handler '/var/www/apps/songs/random.rb';
}
location /words/random {
mruby_content_handler '/var/www/apps/words/random.rb';
}
}
begin
row = `sqlite3 /var/www/apps/shared/songs.db "SELECT * FROM songs ORDER BY RANDOM() LIMIT 1;"`
row = row.split('|')
song = {
id: row[0],
artist: row[1],
title: row[2],
listen_url: row[3],
post_url: row[4],
tags: row[5],
created_at: row[6]
}
Nginx::rputs JSON::stringify({ song: song })
rescue Exception => e
Ngixn::rputs e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment