<commit_before># -*- encoding: UTF-8 -*-

require 'rack'
require 'coffee-script'
require 'sprockets'

module Peaberry
  class DotJs

    def initialize
      @sprockets = Sprockets::Environment.new
      dot_js_dir = File.expand_path('~/.js')
      @sprockets.append_path(dot_js_dir)
    end

    def call(env)
      request = Rack::Request.new(env)
      files = []
      files << @sprockets.find_asset('default.js')
      files << @sprockets.find_asset(request.path_info.sub(/^\//, ''))
      body = "// dotjs is working! //\n" + files.compact.map(&:to_s).join
      status_code = 200
      headers = {
        'Content-Length' => body.bytesize.to_s,
        'Content-Type' => 'text/javascript',
        'Access-Control-Allow-Origin' => '*'
      }
      [ status_code, headers, body.lines ]
    end
  end
end<commit_msg>Log and respond with 500 on an exception.<commit_after># -*- encoding: UTF-8 -*-

require 'rack'
require 'coffee-script'
require 'sprockets'

module Peaberry
  class DotJs

    def initialize
      @sprockets = Sprockets::Environment.new
      dot_js_dir = File.expand_path('~/.js')
      @sprockets.append_path(dot_js_dir)
    end

    def call(env)
      request = Rack::Request.new(env)
      files = []
      files << @sprockets.find_asset('default.js')
      files << @sprockets.find_asset(request.path_info.sub(/^\//, ''))

      body = "// dotjs is working! //\n" + files.compact.map(&:to_s).join
      headers = {
        'Content-Length' => body.bytesize.to_s,
        'Content-Type' => 'text/javascript',
        'Access-Control-Allow-Origin' => '*'
      }
      [ 200, headers, body.lines ]
    rescue => e
      logger.error(e.message)
      [ 500, {}, [''] ]
    end
  end
end
{'fraction_non_alphanumeric': 0.1587857559836544, 'fraction_numerical': 0.008172796263864565, 'mean_word_length': 2.512295081967213, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2605415', 'n_tokens_mistral': 624, 'n_tokens_neox': 595, 'n_words': 108}