0

I'm trying to add a route to my dashing application that will receive data from a webhook.

I tried using the solution here, and while that did create the route, it broke the dashing dashboard at '/sample'.

Any ideas?

Here is my lib/app.rb:

require 'sinatra/base'

class App < Sinatra::Base

  get '/callback' do
    "Callback route."
  end

end

Here is my config.ru:

require 'dashing'

configure do
  set :auth_token, 'YOUR_AUTH_TOKEN'

  helpers do
    def protected!
      # Put any authentication code you want in here.
      # This method is run before accessing any resource.
    end
  end
end

map Sinatra::Application.assets_prefix do
  run Sinatra::Application.sprockets
end

run Sinatra::Application
run App

UPDATE:
I changed the route name to something obscure (so that the mount for sure doesn't use it). It looks like whichever run command I put last is the one that takes effect. The route works if run App is last, the dashboard works if run Sinatra::Application is last. But when one works, the other doesn't

  • Maybe it's because routes cascade, e.g. if you have a `get '/:id'` before the `get '/sample'` route, the second will never get hit, because it is caught in the `:id` wildcard. So you could try changing the order or the routes, or the order they are run in config.ru. Anyway, you should show your code in the question, it's not enough info to help you much now. – max pleaner Aug 29 '17 at 18:28
  • I added the code to my original post. I don't think that is my issue because I'm making a fixed route '/callback' and now something with a parameter. – testing_josh Aug 29 '17 at 19:25
  • did you try changing the order of the `run` calls in config.ru? Or changing the name of the route you're adding? Beyond that, I don't know. – max pleaner Aug 29 '17 at 19:33
  • I changed the route name to something obscure (so that the mount for sure doesn't use it). It looks like whichever run command I put last is the one that takes effect. The route works if `run App` is last, the dashboard works if run `Sinatra::Application` is last. But when one works, the other doesn't. – testing_josh Aug 29 '17 at 19:39

1 Answers1

0

You can run different apps inside your config.ru.

Inside your config.ru, replace

map Sinatra::Application.assets_prefix do
  run Sinatra::Application.sprockets
end

run Sinatra::Application
run App

with

map('/') { run App }
map('/sample') { run Sinatra::Application }
map(Sinatra::Application.assets_prefix) { run Sinatra::Application.sprockets }

It's important to note that by doing this, rack is going to be handling the route prefixes. So if you navigated to /sample, The sinatra app run under that route will see that as /.

config.ru is actually run in a Rack::Builder context. So the above is equivalent to

apps = Rack::Builder.new do 
     map('/') { run App }
     map('/sample') { run Sinatra::Application }
     map(Sinatra::Application.assets_prefix) { run Sinatra::Application.sprockets }
end
run apps
Cereal
  • 3,699
  • 2
  • 23
  • 36