webdap/server.rb

61 lines
1.0 KiB
Ruby

# frozen_string_literal: true
require 'logger'
require 'sinatra/base'
require 'rack/protection'
# Base Sinatra app
class Webdap < Sinatra::Base
@@my_app = {}
def self.new(*)
self < Webdap ? super : Rack::URLMap.new(@@my_app)
end
def
self.map(url) @@my_app[url] = self
end
configure do
enable :sessions
# Enable rack protection middleware
use Rack::Protection
# Set up static file serving
enable :static
set :public_folder, File.join(settings.root, '/public')
# Set up our view engine
set :views, File.join(settings.root, '/views')
end
# Initialize logging
logger = Logger.new($stdout)
logger.level = Logger::INFO
# Load helper functions
require_relative 'app/helpers'
helpers Helpers
## Map controllers
# Top-level routes controller
class IndexController < Webdap
map '/'
end
# Authentication routes controller
class AuthController < Webdap
map '/auth'
end
end
# Load controllers
Dir.glob('./app/controllers/*.rb').sort().each { |f| require f }