Sha256: 53d85a36b5552635dfc9226a3b5786a4d4dac55c43efdab0aa01cc77e37b0ab4

Contents?: true

Size: 1006 Bytes

Versions: 1

Compression:

Stored size: 1006 Bytes

Contents

$:.unshift File.expand_path '../../../lib', __FILE__

require 'angelo'
require 'angelo/tilt/erb'

class Foo < Angelo::Base
  include Angelo::Tilt::ERB

  TEST = {foo: "bar", baz: 123, bat: false}.to_json

  def pong; 'pong'; end
  def foo; params[:foo]; end
  def time_ms; Time.now.to_f * 1000.0; end

  before do
    info "request: #{request.method} #{request.path}"
    @foo = request.path
    @timing = time_ms
  end

  after do
    info "timing: #{time_ms - @timing}ms"
  end

  get '/' do
    @name = params[:name]
    @host = request.headers['Host']
    erb :index, locals: {zzz: 'word'}
  end

  get '/ping' do
    debug "@foo: #{@foo}"
    pong
  end

  post '/foo' do
    foo
  end

  post '/bar' do
    content_type = :json
    params
  end

  post '/emit' do
    websockets.each {|ws| ws.write TEST}
    params.to_json
  end

  socket '/ws' do |s|
    websockets << s
    while msg = s.read
      5.times { s.write TEST }
      s.write foo.to_json
    end
  end

end

Foo.run unless $0 == 'irb'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
angelo-0.0.4 example/foo/foo.rb