Sha256: edb548e09e10f6268eb02eb19f4956bba3d615d2e6cfb807a851001469bcc154
Contents?: true
Size: 1010 Bytes
Versions: 2
Compression:
Stored size: 1010 Bytes
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'] if container composer = app.presenter.composer body = composer.container(container.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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pakyow-realtime-0.10.1 | pakyow-realtime/lib/pakyow-realtime/message_handlers/call_route.rb |
pakyow-realtime-0.10.0 | pakyow-realtime/lib/pakyow-realtime/message_handlers/call_route.rb |