0

I am developing a simple web app using Sinatra and using rack as the middleware and hence have a config.ru. To run the application I use shotgun config.ru.

I have no problem when the application does a GET request. But my app has a couple of POST requests, and when I submit a form via POST method, I get this strange error:

Method Not Allowed

Following is the content of my config.ru:

require "rack"
require 'rack/contrib/try_static'
require File.expand_path("app", File.dirname(__FILE__))

use Rack::TryStatic, :root => File.join(App::SETTINGS.source, App::SETTINGS.site.config['destination']), :urls => %w[/]

run App

Any idea what could resolve the issue?

Thank You

swaroopsm
  • 1,389
  • 4
  • 18
  • 34

2 Answers2

0

The following will not respond to posts:

get '/hi' do
 "Hello World!"
end

It is quite possible that you will need to do something like this:

post '/hi' do
  # do post stuff
end
mcmorgan
  • 26
  • 2
0

I solved the issue. It was a problem with rack.

I replaced

use Rack::TryStatic, 
    :root => File.join(App::SETTINGS.source, App::SETTINGS.site.config['destination']), 
    :urls => %w[/]

with:

use Rack::Static,
    :urls => ["/#{App::SETTINGS.site.config['destination']}"],
    :root => File.join(App::SETTINGS.source, App::SETTINGS.site.config['destination'])
swaroopsm
  • 1,389
  • 4
  • 18
  • 34
  • The options you've given are different, and [TryStatic calls Static under the hood anyway](https://github.com/rack/rack-contrib/blob/1.1.0/lib/rack/contrib/try_static.rb#L21). – ian Dec 21 '13 at 19:37
  • That's true. But TryStatic will give you a 405 error for any requests other than a `GET`. – swaroopsm Dec 22 '13 at 05:05
  • Because static pages are only supposed to be called with a GET. They're static and require no processing. You've used `:urls` with `%w[/]` instead of `:try` which means the middleware will intercept *all* requests, so and POST et al routes that you've defined will not be reached. – ian Dec 22 '13 at 11:51
  • I have changed the urls option. Did you check the answer? – swaroopsm Dec 23 '13 at 03:23