Sha256: 4d7c3f9a0f91ee8288a0aa2842c5b472d7723cc1aa3908d20f83ba35204a429e
Contents?: true
Size: 1.27 KB
Versions: 6
Compression:
Stored size: 1.27 KB
Contents
require "rack" require 'webrick' require 'json' require 'uri' require_relative '../rule_engine' require_relative '../visitors/configuration_visitor' require_relative '../facades/configuration_page_facade' require_relative '../facades/configuration_file_facade' class LinterServer def call(env) req = Rack::Request.new(env) case req.path when "/configuration" if req.post? process_form(req) elsif req.get? configurations_page end end end def configurations_page configuration_page = ConfigurationPageFacade.AssemblePage return [200, { 'Content-Type' => 'text/html' }, [configuration_page]] end def process_form(req) new_conf = URI.decode_www_form(req.body.read) new_conf_hash = Hash[new_conf.map {|key, value| [key, value]}] begin ConfigurationPageFacade.ApplyConfigurations(new_conf_hash) ConfigurationFileFacade.SaveConfigurations rescue StandardError => error return [400, { 'Content-Type' => 'text/plain' }, ["Error: #{error.message}"]] end return [200, { 'Content-Type' => 'text/plain' }, ["Changes saved successfully"]] end def self.start(port) log = WEBrick::Log.new $stdout,1 Rack::Handler::WEBrick.run(LinterServer.new, :Port => port,Logger: log ) end end
Version data entries
6 entries across 6 versions & 1 rubygems