<commit_before>require 'webrick'
require 'yabass/renderer'

module Yabass
  module Server
    class << self
      def start(router)
        server = WEBrick::HTTPServer.new({ DocumentRoot: './',
                                           BindAddress: '127.0.0.1',
                                           Port: 3030})
        server.mount_proc('/') do |req, res|
          found_page = router.pages.find{|page| /^#{page.route}\/?$/ =~ req.path }
          file_path = File.expand_path("public/#{req.path}", ::Yabass::root)
          index_path = "#{file_path}/index.html"
          if found_page
            res.body = Renderer.render(found_page.file_path, found_page.data, found_page.parent)
            res.content_type = 'text/html'
            res.status = 200
          elsif File.file?(file_path)
            res.body = File.read(file_path)
            mime = WEBrick::HTTPUtils.mime_type(file_path, WEBrick::HTTPUtils::DefaultMimeTypes)<commit_msg>Added redirection rule to yabass server<commit_after>require 'webrick'
require 'webrick/httpstatus'
require 'yabass/renderer'

module Yabass
  module Server
    class << self
      def start(router)
        server = WEBrick::HTTPServer.new({ DocumentRoot: './',
                                           BindAddress: '127.0.0.1',
                                           Port: 3030})
        server.mount_proc('/') do |req, res|
          found_page = router.pages.find{|page| /^#{page.route}\/?$/ =~ req.path }
          file_path = File.expand_path("public/#{req.path}", ::Yabass::root)
          index_path = "#{file_path}/index.html"
          if found_page
            if /.\/$/ =~ req.path
              res.body = Renderer.render(found_page.file_path, found_page.data, found_page.parent)
              res.content_type = 'text/html'
              res.status = 200
            else # Redirect to directory index path
              res['Pragma'] = 'no-cache'
              res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, "#{found_page.route}/")
            end
          elsif File.file?(file_path)
            res.body = File.read(file_path)
            mime = WEBrick::HTTPUtils.mime_type(file_path, WEBrick::HTTPUtils::DefaultMimeTypes)
{'fraction_non_alphanumeric': 0.12929475587703435, 'fraction_numerical': 0.011754068716094032, 'mean_word_length': 1.9664879356568365, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '727721', 'n_tokens_mistral': 679, 'n_tokens_neox': 668, 'n_words': 117}