raven/server.rb

71 lines
1.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'logger'
require 'sequel'
require 'sqlite3'
require 'sinatra/base'
require 'rack/protection'
# Load the Sequel timestamps plugin
Sequel::Model.plugin(:timestamps)
# Initialize Sequel gem for database actions
DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get('database.database'))
# Load models
Dir.glob('./app/models/*.rb').sort().each { |f| require f }
# Base Sinatra app
class Raven < Sinatra::Base
@@my_app = {}
def self.new(*) self < Raven ? super : Rack::URLMap.new(@@my_app) end
def self.map(url) @@my_app[url] = self end
# Enable and configure sessions
enable :sessions
# Enable rack protection middleware
use Rack::Protection
# Set up static file serving
enable :static
set :public_folder, File.join(__dir__, '/public')
# Set up our view engine
set :views, File.join(settings.root, '/views')
# 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 < Raven
map '/'
end
# Item routes controller
class ItemController < Raven
map '/item'
end
# License routes controller
class LicenseController < Raven
map '/license'
end
# Search routes controller
class SearchController < Raven
map '/search'
end
# IP tracker routes controller
class IpTrackerController < Raven
map '/ip-tracker'
end
end
# Load controllers
Dir.glob('./app/routes.rb').sort().each { |f| require f }