RubyUtils/lib/web.rb

48 lines
1.1 KiB
Ruby

module Systems
end
Dir[File.join(__dir__, 'systems', '*.rb')].each { |file| require file }
# Static file serving in this file because it is overkill to create a file for this
class Systems::PublicSystem < Sinatra::Base
set :public_folder, "public"
end
# Main app
class App < Sinatra::Base
DocMyRoutes.configure do |config|
config.title = "NetProbed"
config.description = "NetProbed JSON REST API documentation"
end
set :session_secret, SECRET
enable :sessions
set :protection, except: :json_csrf if APP_ENV != "test"
Systems.constants
.filter { |system| system.to_s =~ /System$/ }
.each { |system|
use Systems.const_get(system)
puts "Loaded #{system.to_s.green}"
}
# include JSON::API
not_found do
# if accept_json?
# { message: "No route or entity \"#{request.path}\" found" }.to_json
# else
raise
# end
end
# get "/api/meta/v1", provides: "json" do
# ::ApiList.get_all_api_routes.to_json
# end
set :bind, ENV["BIND"] || "127.0.0.1"
set :port, ENV["PORT"] || 4567
set :environment, APP_ENV
ENV["RACK_ENV"] = APP_ENV
end