Last active
August 29, 2015 13:56
-
-
Save zorbash/9125554 to your computer and use it in GitHub Desktop.
nginx + mruby experiment, /songs/random endpoint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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