Question

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

Was it helpful?

Solution 2

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'])

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top