Created
February 23, 2012 12:54
-
-
Save tzangms/1892695 to your computer and use it in GitHub Desktop.
DjangoHandler for FireApp
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
| module WEBrick | |
| module HTTPServlet | |
| class DjangoHandler < AbstractServlet | |
| def initialize(server, name) | |
| super(server, name) if( server ) | |
| @root_path = Compass.configuration.project_path | |
| @script_filename = name | |
| end | |
| ## | |
| # Handles GET requests | |
| def do_GET(req, res) | |
| begin | |
| res.body = parse(req, res) | |
| res['content-type'] ||= | |
| HTTPUtils::mime_type(@script_filename, @config[:MimeTypes]) | |
| rescue StandardError => ex | |
| raise | |
| rescue Exception => ex | |
| @logger.error(ex) | |
| raise HTTPStatus::InternalServerError, ex.message | |
| end | |
| end | |
| ## | |
| # Handles POST requests | |
| alias do_POST do_GET | |
| def parse(req, res) | |
| %x{/bin/bash -c "/usr/local/bin/firedj #{@script_filename}"} | |
| end | |
| end | |
| end | |
| end | |
| WEBrick::HTTPServlet::FileHandler.add_handler("html", WEBrick::HTTPServlet::DjangoHandler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment