view · edit · sidebar · attach · print · history

< Niklaus.20161017-steinwies-rack | Index | Niklaus.20161011-steinwies-rack >>

20161012-steinwies-rack

Summary

  • port sbsm/steinwies.ch to use the rack webserver
  • Keep in Mind

Commits

Index

port sbsm/steinwies.ch to use the rack webserver

SBSM has not test code for stuff like cookies, redirect, passthru, remote_host. Looking whether it is easy to add tests for these points.

steinwies.ch returns the following cookies (name, value, path, domain, expiration date)

  _session_id     408e56abd4f72a9c694762e356b09da8        /       steinwies.ch    End Of Session
  sbsm-persistent-cookie  language%3Den   /       steinwies.ch    10.10.2026, 08:35:321

Okay. The old apache config for mod_ruby contained a definition of RubyTransHandler Steinwies::TransHandler.instance. This is missing now. In the source code of mod_ruby I find the lines

    AP_INIT_TAKE1("RubyTransHandler", ruby_cmd_trans_handler, NULL, OR_ALL,
     "set translation handler object"),
    <..>
  static int ruby_trans_handler(request_rec *r)                               
  {                                                                           
    ruby_dir_config *dconf = get_dir_config(r);                           

    return ruby_handler(r, dconf->ruby_trans_handler, NULL,              
                        rb_intern("translate_uri"), 0, 0);          
  }                                                                          

This is used to translate the uri. Adapted SBSM::Request.new to use the following parameters def initialize(drb_uri, trans_handler, env, html_version = "html4"). I think this is much clearer. Also added the following lines at the beginning of sbsm/request/process

        file_name = File.expand_path(File.join('doc', @request.path))
        if File.file?(file_name)
          if /css/i.match(File.basename(file_name))
            @response.set_header('Content-Type', 'text/css')
          else
            @response.set_header('Content-Type', 'text/plain')
          end
          @response.write(File.open(file_name, File::RDONLY){|file| file.read})
          return @response
        end

The hard coded value of doc must still be replaced by a configuration value (or at least be possible to override). Also creating a config.ru file (instead of the doc/index.rbx) to start the WebServer. Content is

  #!/usr/bin/env ruby
  require 'sbsm/request'
  lib_dir = File.expand_path(File.join(File.dirname(__FILE__), 'src').untaint)
  $LOAD_PATH << lib_dir
  require 'util/app'
  # DRb.start_service('druby://localhost:0')

  require 'rack'
  require 'rack/show_exceptions'

  Rack::Server.start(
    :app => Rack::ShowExceptions.new(Rack::Lint.new(Rack::Steinwies.new)),
    :Port => 9292,
  )

Now the steinwie page displays correctly the home page, but navigation to a sub page always displays the home page. This must be correct.

Nota bene: Webserver is now being started using sudo -u apache /usr/local/bin/bundle exec rackup

Tried half an hour to use the rack-test gem to test sbsm. But it proved not so easy. Must begin again another time with a fresh mind.

Search a long time on where to add calls to the translate_uri. It still does not work and somehow wants to got from steinwies2.ngiger.ch -> steinwies.ch. Looks like the servername is not get set correctly. This was fixed by changing the line server_name: steinwies2.ngiger.ch in etc/config.yaml. But we still do display the correct site, eg. http://steinwies2.ngiger.ch/en/page/person/ still has the same content as http://steinwies2.ngiger.ch. Will fix this next week.

Saved my changes in the rack branches with commits:

Just stumbled via Ruby weekly on an article to build a Rack webserver in ruby. See https://ksylvest.com/posts/2016-10-04/building-a-rack-web-server-in-ruby?utm_source=rubyweekly&utm_medium=email

view · edit · sidebar · attach · print · history
Page last modified on October 13, 2016, at 10:16 AM