Add routes to Dashing dashboard

假如想象 提交于 2019-12-12 00:35:36

问题


How do I add a route in my dashboard that I can access, for example...

get '/:id' do
  protected!
  return params[:'id']
end

Which I can call from http://localhost:3030?id=1234


回答1:


The easiest way to do this would be to define a new application and call it inside the config.ru that gets created by Dashing. For instance, I created a new file called my_app.rb in a dashing repo with the following contents:

# my_app.rb

require 'sinatra/base'

class MyApp < Sinatra::Base
  get '/:id' do
    "My own custom route! And the id is #{params[:id]}"
  end
end

And included that app inside the config.ru like so:

# Created by dashing until Sinatra::Application
…
run Sinatra::Application

# added by us
run MyApp

And then when you run dashing start, the route we defined in our app gets called. But there's a problem with this approach in that you need to ensure that the routes being defined in MyApp won't conflict with those already defined by dashing. The other way to solve this is to let dashing run on a path other than the default /. There is a bit of documentation for this approach in the Wiki.



来源:https://stackoverflow.com/questions/36877633/add-routes-to-dashing-dashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!