Sha256: 07c1e4065f466b1167a82268a38d100880e7375ff30a0ca8f5e8d82c92d2bde4
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
require 'erb' module Adminix module Web class Server < EM::HttpServer::Server def process_http_request # puts @http_request_method # puts @http_request_uri # puts @http_query_string # puts @http_protocol # puts @http_content # puts @http[:cookie] # puts @http[:content_type] # you have all the http headers in this hash # puts @http.inspect process_request end def http_request_errback(e) # printing the whole exception puts e.inspect end # Routes def not_found_route content = 'Page not found' render text: content, status: 404 end # Helpers private def render(opts) res = if opts[:html] construct_response(opts[:html], content_type: 'text/html') elsif opts[:text] construct_response(opts[:text]) elsif opts[:json] construct_response(opts[:json], content_type: 'application/json') end res.send_response end def construct_response(content, opts = {}) res = EM::DelegatedHttpResponse.new(self) res.status = opts[:status] || 200 res.content_type opts[:content_type] || 'text/plain' res.content = content res end def view(path) Helpers::Files.read_erb_tpl(path, binding) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
adminix-0.2 | lib/adminix/web/server.rb |