jeremyevans / roda

Routing Tree Web Toolkit
http://roda.jeremyevans.net
MIT License
2.08k stars 141 forks source link

opts[:root] not be set after start server. #212

Closed zw963 closed 3 years ago

zw963 commented 3 years ago

Hi, i saw following document in mastering roda.

:root sets the root path to the application in the file system. It is used for setting default paths for various parts of the application. It defaults to the current working directory of the process, so if our Roda application is being run from a different directory, we should definitely set this.

But, i test it with rackup, puma, or Procofile, all opts[:root] return nil.

in fact, i can't see any key name match root, following is my opts

{
          :default_headers => {
        "Content-Type" => "text/html; charset=UTF-8"
    },
                   :render => {
                       :escape => true,
                    :orig_opts => {
            :escape => true
        },
                       :engine => "erb",
                        :views => "/home/zw963/Stocks/marketbet_crawler/views",
                :allowed_paths => [
            "/home/zw963/Stocks/marketbet_crawler/views"
        ],
                  :check_paths => true,
         :check_template_mtime => true,
        :template_method_cache => #<Roda::RodaCache:0x000055fe1d28adb8 @mutex=#<Thread::Mutex:0x000055fe1d28abd8>, @hash={}>,
                        :cache => #<Roda::RodaCache:0x000055fe1d28aac0 @mutex=#<Thread::Mutex:0x000055fe1d28a9f8>, @hash={}>,
                  :layout_opts => {
            :_is_layout => true,
              :template => "layout"
        },
                       :layout => true,
              :optimize_layout => "layout",
                :template_opts => {
                      :outvar => "@_out_buf",
            :default_encoding => #<Encoding:UTF-8>,
                      :escape => true
        },
                  :engine_opts => {}
    },
       :append_content_for => true,
       :path_class_by_name => true,
             :path_classes => {
        "String" => #<Proc:0x000055fe1d963d60 /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/roda-3.46.0/lib/roda/plugins/path.rb:80>
    },
       :path_class_methods => {
        "String" => :_roda_path_String_1
    },
                   :assets => {
                          :css => [
            "app.scss"
        ],
                           :js => [
            "app.js"
        ],
                    :orig_opts => {
            :css => [
                "app.scss"
            ],
             :js => [
                "app.js"
            ]
        },
                         :path => "/home/zw963/Stocks/marketbet_crawler/assets",
                       :public => "/home/zw963/Stocks/marketbet_crawler/public",
                :compiled_name => "app",
                       :js_dir => "js",
                      :css_dir => "css",
                       :prefix => "assets",
                  :concat_only => false,
                     :compiled => false,
                   :add_suffix => false,
                  :early_hints => false,
              :timestamp_paths => false,
                :group_subdirs => true,
             :compiled_css_dir => nil,
              :compiled_js_dir => nil,
                          :sri => :sha256,
                :compiled_path => "assets",
                     :js_route => "js",
                    :css_route => "css",
            :compiled_js_route => nil,
           :compiled_css_route => nil,
                  :css_headers => {
            "Content-Type" => "text/css; charset=UTF-8"
        },
                   :js_headers => {
            "Content-Type" => "application/javascript; charset=UTF-8"
        },
                     :css_opts => {},
                      :js_opts => {},
                 :dependencies => {},
        :expanded_dependencies => {},
                      :js_path => "/home/zw963/Stocks/marketbet_crawler/assets/js/",
                     :css_path => "/home/zw963/Stocks/marketbet_crawler/assets/css/",
             :compiled_js_path => "/home/zw963/Stocks/marketbet_crawler/public/assets/app",
            :compiled_css_path => "/home/zw963/Stocks/marketbet_crawler/public/assets/app",
                    :js_prefix => "assets/js/",
                   :css_prefix => "assets/css/",
           :compiled_js_prefix => "assets/app",
          :compiled_css_prefix => "assets/app",
                    :js_suffix => "",
                   :css_suffix => ""
    },
    :error_handler_classes => [
        StandardError < Exception,
        ScriptError < Exception
    ],
           :status_handler => {
        404 => [
            :_roda_status_handler_404,
            0
        ]
    }
}

Please check my repo source code here for reproduce:

https://github.com/zw963/marketbet_crawler

Roda: 3.4.6 Ruby 3.0.2 puma 5.3.2

Thank you.

jeremyevans commented 3 years ago

This is expected. If you don't provide a value for :root, the default value that is used when a root directory is needed is the current working directory of the process. However, Roda does not explicitly set the :root option (or any other options).

zw963 commented 3 years ago

the default value that is used when a root directory is needed is the current working directory of the process.

Don't understand clear, sorry, so, if we want get this default value in a roda app, how to do that?

jeremyevans commented 3 years ago

Dir.pwd returns the current working directory of the process.