【发布时间】:2016-10-14 07:15:07
【问题描述】:
这是我正在构建的真实应用的精简示例。当我执行我的应用程序时,这就是我得到的结果。您会注意到它说它在启动之前正在运行。您还会注意到它在 start 发出后从不说 running。
bundle exec rackup
Using thin;
Sapp::App running.
Starting Sapp::App
== Sinatra (v1.4.7) has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop
我的 config.ru 是:
# http://www.rubydoc.info/gems/webmachine/Webmachine/Adapters/Rack
$started = false
require 'thin'
require 'sinatra'
set :server, (ENV['RACK_ENV'] == 'production' || ENV['RACK_ENV'] == 'staging' ? 'rack' : 'thin')
puts "Using #{settings.server};"
load 'webmachine/adapters/rack.rb'
load File.join(File.dirname(__FILE__), 'sapp.rb')
$started = true
puts 'Starting Sapp::App'
#Sapp::App.run!
Sinatra::Application.run!
我设置 $started 只是为了尝试解决这个问题,但这并没有帮助。我的应用程序在设置之前执行。我可以控制它,但是,这就是问题所在,在运行发出后它不会执行。
sapp.rb 是:
ENV['RACK_ENV'] ||= 'development'
Bundler.setup
$: << File.expand_path('../', __FILE__)
$: << File.expand_path('../lib', __FILE__)
require 'dotenv'
Dotenv.load(
File.expand_path("../.env.#{ENV['RACK_ENV']}", __FILE__),
File.expand_path("../.env", __FILE__))
module Sapp
class App < Sinatra::Application
puts 'Sapp::App has been started.' if $started
puts 'Sapp::App running.'
end
end
最后,如果没有别的,一旦它说“正在启动 Sapp::App”,它也应该说“Sapp::App 已启动”。和“Sapp::App 正在运行。”
为了记录,这两个选项做同样的事情:
Sapp::App.run!
Sinatra::Application.run!
【问题讨论】: