Rackup File
You can use the rackup_file
middleware to mount a rack application defined in a Rackup file (typically config.ru
)
The alternative way to mount a rack application is to use the run
middleware to define a Rack app inline.
You can mount several rack applications to run simultaneously within a single Itsi application, using different location blocks.
Depending on where you mount the app, the application will receive different values for PATH_INFO
, SCRIPT_NAME
.
Itsi.rb
file is defined, Itsi will attempt to run the app defined at ./config.ru
by default, just like other Rack servers. You can also use -r
or --rackup_file
flags to specify a different file.Configuration
Simple inline Rackup file.
rackup_file "config.ru"
Rack app mounted at a subpath
require 'rack'
location "/subpath/*" do
rackup_file "config.ru"
end
rackup_file "config.ru"
# SCRIPT_NAME is "/subpath", path_info is "/child_path"
$ curl http://0.0.0.0:3000/subpath/child_path
# SCRIPT_NAME is "", path_info is "/root/child_path"
$ curl http://0.0.0.0:3000/root/child_path
:/root/child_path
SCRIPT_NAME
and PATH_INFO
Rack ENV variables.
Rack applications mounted at a subpath will, by default, receive a SCRIPT_NAME
value that includes the subpath at which the app is mounted, and a PATH_INFO
value that is relative to the subpath at which the rack app is mounted.
If you wish to use location blocks only to control the middleware that applies to a rack app, but still have it behave as if it were mounted elsewhere (e.g. at the root), you can explicitly set the script_name
option.
E.g.
location "/subpath/*" do
rackup_file "config.ru", script_name: '/'
end
# Our script-name override kicks in here, even though the app is mounted under `/subpath`
$ curl http://0.0.0.0:3000/subpath/child_path
/:/subpath/child_path
Options
nonblocking
(default false). Determines whether requests sent to this Rack application should be run on non-blocking threads. Only applies if running in hybrid (non-blocking and blocking thread pool) mode. Otherwise this is a no-op and will run in whatever mode is set globally.sendfile
(default true). Determines whether Itsi should respect theX-Sendfile
header set by the Rack application and use thesendfile
function to efficiently send files. (Despite the name, this does not use the OS-levelsendfile
system call). Note. Itsi enforces the restriction that the referenced file must be within a child directory of the application root.
e.g.
rackup_file "config.ru", nonblocking: true, sendfile: false