Class: Vue::Helpers::Server
- Inherits:
-
Object
- Object
- Vue::Helpers::Server
- Defined in:
- lib/vue/helpers/server.rb
Overview
Rack middleware to serve sourced vue block, see redpanthers.co/rack-middleware/. Usage: use Vue::Helpers::Server
Instance Method Summary collapse
- #call(env) ⇒ Object
- #get_content(key) ⇒ Object
-
#initialize(app) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(app) ⇒ Server
Returns a new instance of Server.
13 14 15 |
# File 'lib/vue/helpers/server.rb', line 13 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vue/helpers/server.rb', line 17 def call(env) req = Rack::Request.new(env) case req.path_info #when /^\/vuesource\/([A-Za-z0-9\-_]{43})$/ when /^#{Vue::Helpers.callback_prefix}\/([A-Za-z0-9\-_]{43})$/ #puts "vue_source match: #{$1}" if content = get_content($1) [200, {"Content-Type" => "text/javascript"}, [content]] else [404, {"Content-Type" => "text/html"}, ['']] end when /^\/pingm$/ [200, {"Content-Type" => "text/javascript"}, ['Ok']] else #[404, {"Content-Type" => "text/html"}, ["I'm Lost!"]] @app.call(env) end end |