Class: Itsi::Server::Config::StaticAssets
- Inherits:
-
Middleware
- Object
- Middleware
- Itsi::Server::Config::StaticAssets
- Defined in:
- lib/itsi/server/config/middleware/static_assets.rb
Constant Summary collapse
- ErrorResponse =
TypedStruct.new do { error: Type(ErrorResponseDef) & Required() } end
- IndexResponse =
TypedStruct.new do { index: Type(String) & Required() } end
- RedirectResponse =
TypedStruct.new do { redirect: Type(Redirect::Redirect) & Required() } end
Instance Method Summary collapse
Methods included from ConfigHelpers
included, #initialize, load_and_register, #normalize_keys!
Instance Method Details
#build! ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/itsi/server/config/middleware/static_assets.rb', line 63 def build! root_dir = @params[:root_dir] || "." if !File.exist?(root_dir) raise "Warning: static_assets root_dir '#{root_dir}' does not exist!" elsif !File.directory?(root_dir) raise "Warning: static_assets root_dir '#{root_dir}' is not a directory!" end @params[:relative_path] = true unless @params.key?(:relative_path) @params[:allowed_extensions] ||= [] if @params[:try_html_extension] && @params[:allowed_extensions].include?("html") @params[:allowed_extensions] << "" end if @params[:allowed_extensions].any? && @params[:auto_index] @params[:allowed_extensions] |= ["html"] @params[:allowed_extensions] |= [""] end @params[:base_path] = "^(?<base_path>#{location.paths_from_parent.gsub(/\.\*\)$/,")")}).*$" params = @params location.middleware[:static_assets] = params end |