sinatra“GET / HTTP / 1.1”404错误

时间:2016-01-06 20:18:20

标签: ruby-on-rails ruby sinatra

我正在尝试运行一个sinatra应用程序。但我得到的唯一一页是“这不是您正在寻找的页面。”也许我没有正确的URL。任何帮助都会很棒。

http://localhost:9292/

service.rb文件

  public
    helpers do
        def serialize(data, format)
            if format.upcase == "XML"
                classname = data.class.name.split('::').last.downcase
                if classname.upcase == "ARRAY"
                    classname = data.first.class.name.split('::').last.downcase
                    data.to_xml(:root_name => classname, :array_root_name => classname + "s")
                else
                    data.to_xml(:root_name => classname)
                end
            elsif format.upcase == "JSON"
                data.to_json
            else
                classname = data.class.name.split('::').last.downcase
            end
        end
    end

Config.ru文件

require 'rubygems'
require 'sinatra'
require './service'
   require 'pry'


    root_dir = File.dirname(__FILE__)

   set :environment, :production
    set :root, root_dir
    set :app_file, File.join(root_dir, './service.rb')


      FileUtils.mkdir_p 'log' unless File.exists?('log')
        log = File.new("log/sinatra.log", "a")
      $stdout.reopen(log)

     DB = Sequel.connect(
:adapter => 'mysql',
:host => 'localhost',
:database => 'database',
:user => 'user',
:password => 'password')
   IllyriadApi::Service.setDatabase(DB)

  def app
IllyriadApi::Service
  end

  map '/' do
run IllyriadApi::Service
 end

C:\ Users \ dakota \ Desktop \ IllyriadAp> rackup config.ru

[2016-01-06 12:06:24] INFO WEBrick 1.3.1

[2016-01-06 12:06:24] INFO ruby​​ 2.2.3(2015-08-18)[i386-mingw32]

[2016-01-06 12:06:24] INFO WEBrick :: HTTPServer #start:pid = 1196 port = 9292

:: 1 - - [06 / Jan / 2016:12:06:33 -0800]“GET / HTTP / 1.1”404 40 0.1130

Link to the full source of the code just in case

联盟数据库 1“id”H? “自动收报机”无害? “name”2010-02-25“founder_at”14:18:07 10“established_by_player_id”14646“capital_town_id”43“member_count”8651950“total_population”0.000“tax_rate”2012-10-14 18:48:43“tax_rate_last_changed_at”2012 -01-19 17:42:55“capital_town_last_moved_at”

alliance_roles数据库

1“id”创始人“名称”1 [ - >]“alliance_id”1“hierarchy_id”

城镇数据库 1“id”2016-01-05 00:03:31“data_timestamp”1“town_id”Stormont“name”383“location_x”-1815“location_y”2010-02-21 22:08:02“established_at”1“owner_id “12941”人口“1”is_capital“1”is_alliance_capital“

1 个答案:

答案 0 :(得分:3)

对于get/,您需要定义路线

get '/' do
  'Hello world!'
end

hello world替换为您打开页面http://localhost:9292/

时需要运行的任何代码