Sha256: 689ee1003720b8b7b30d88d52e13cad82e37ed1b08ef01eecfe053befe81715b
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
# Calls an app route and returns a response, just like an HTTP request! # Pakyow::Realtime.handler :'call-route' do |message, session, response| path, qs = message['uri'].split('?') path_parts = path.split('/') path_parts[-1] += '.json' uri = [path_parts.join('/'), qs].join('?') env = Rack::MockRequest.env_for(uri, method: message['method']) env['pakyow.socket'] = true env['pakyow.data'] = message['input'] env['rack.session'] = session # TODO: in production we want to push the message to a queue and # let the next available app instance pick it up, rather than # the current instance to handle all traffic on this socket app = Pakyow.app.dup res = app.process(env) container = message['container'] partial = message['partial'] composer = app.presenter.composer if container body = composer.container(container.to_sym).includes(composer.partials).to_s elsif partial body = composer.partial(partial.to_sym).includes(composer.partials).to_s else body = res[2].body end response[:status] = res[0] response[:headers] = res[1] response[:body] = body response end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pakyow-realtime-0.10.2 | pakyow-realtime/lib/pakyow-realtime/message_handlers/call_route.rb |