Sha256: 7868364e7eaaf1c9087a3a8ab75bdcad0896aa73881f034453d703db2251d46a
Contents?: true
Size: 1.51 KB
Versions: 7
Compression:
Stored size: 1.51 KB
Contents
#!/usr/bin/env unicorn -N -Ilib require 'jellyfish' class Jelly include Jellyfish controller_include Module.new{ def dispatch headers_merge 'Content-Type' => 'application/json; charset=utf-8', 'Access-Control-Allow-Origin' => '*' super end def render obj ["#{Jellyfish::Json.encode(obj)}\n"] end } handle Jellyfish::NotFound do |e| status 404 body %Q|{"error":{"name":"NotFound"}}\n| end handle StandardError do |error| jellyfish.log_error(error, env['rack.errors']) name = error.class.name message = error.message status 500 body render('error' => {'name' => name, 'message' => message}) end get '/users' do render [:name => 'jellyfish'] end post '/users' do render :message => "jellyfish #{request.params['name']} created." end put %r{\A/users/(?<id>\d+)} do |match| render :message => "jellyfish ##{match[:id]} updated." end delete %r{\A/users/(?<id>\d+)} do |match| render :message => "jellyfish ##{match[:id]} deleted." end get %r{\A/posts/(?<year>\d+)-(?<month>\d+)/(?<name>\w+)} do |match| render Hash[match.names.zip(match.captures)] end get '/posts/tags/ruby' do render [] end end App = Jellyfish::Builder.app do use Rack::CommonLogger use Rack::Chunked use Rack::ContentLength use Rack::Deflater run Rack::Cascade.new([Rack::File.new('public/index.html'), Rack::File.new('public'), Jelly.new]) end run App
Version data entries
7 entries across 7 versions & 1 rubygems
Version | Path |
---|---|
jellyfish-1.3.1 | config.ru |
jellyfish-1.3.0 | config.ru |
jellyfish-1.2.2 | config.ru |
jellyfish-1.2.1 | config.ru |
jellyfish-1.2.0 | config.ru |
jellyfish-1.1.1 | config.ru |
jellyfish-1.1.0 | config.ru |