西纳特拉 "GET / HTTP/1.1" 404 错误
sinatra "GET / HTTP/1.1" 404 error
我正在尝试 运行 sinatra 应用程序。但我得到的唯一页面是 "This is not the page you're looking for." 也许我没有做对 URL。任何帮助都会很棒。
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>架子config.ru
[2016-01-06 12:06:24] 信息 WEBrick 1.3.1
[2016-01-06 12:06:24] 信息 ruby 2.2.3 (2015-08-18) [i386-mingw32]
[2016-01-06 12:06:24]信息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" 哈? "ticker" 无害? "name" 2010-02-25 "founded_at" 14:18:07 10 "founded_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" 创始人 "name" 1 [->] "alliance_id" 1 "hierarchy_id"
城镇数据库
1 "id" 2016-01-05 00:03:31 "data_timestamp" 1 "town_id" 斯托蒙特 "name" 383 "location_x" -1815 "location_y" 2010-02- 2122:08:02"founded_at"1"owner_id"12941"population"1"is_capital"1"is_alliance_capital"
对于get
到/
,你需要定义路由
get '/' do
'Hello world!'
end
将 hello world
替换为打开页面时 运行 所需的任何代码 http://localhost:9292/
我正在尝试 运行 sinatra 应用程序。但我得到的唯一页面是 "This is not the page you're looking for." 也许我没有做对 URL。任何帮助都会很棒。
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>架子config.ru
[2016-01-06 12:06:24] 信息 WEBrick 1.3.1
[2016-01-06 12:06:24] 信息 ruby 2.2.3 (2015-08-18) [i386-mingw32]
[2016-01-06 12:06:24]信息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" 哈? "ticker" 无害? "name" 2010-02-25 "founded_at" 14:18:07 10 "founded_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" 创始人 "name" 1 [->] "alliance_id" 1 "hierarchy_id"
城镇数据库 1 "id" 2016-01-05 00:03:31 "data_timestamp" 1 "town_id" 斯托蒙特 "name" 383 "location_x" -1815 "location_y" 2010-02- 2122:08:02"founded_at"1"owner_id"12941"population"1"is_capital"1"is_alliance_capital"
对于get
到/
,你需要定义路由
get '/' do
'Hello world!'
end
将 hello world
替换为打开页面时 运行 所需的任何代码 http://localhost:9292/