53 lines
1.4 KiB
Ruby
Executable File
53 lines
1.4 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require "sinatra/base" # web
|
|
require "sinatra/cookies"
|
|
require "slim"
|
|
require "sinatra/namespace" # api
|
|
require "doc_my_routes" # api doc
|
|
require "bcrypt" # security
|
|
require "jwt"
|
|
require "rack/csrf"
|
|
require "securerandom"
|
|
require "sequel" # db
|
|
require "json" # helpers
|
|
require "active_support"
|
|
require "active_support/core_ext"
|
|
require "pry" if ENV["DEBUG"] == "true" # debug
|
|
|
|
# Load environment variables
|
|
require_relative "./utils/env"
|
|
APP_ENV = load_dotenv
|
|
|
|
# Initialize framework
|
|
require_relative "./utils/url"
|
|
require_relative "./utils/boot_framework"
|
|
BootFramework.boot_application do
|
|
harshly_need_env "DB"
|
|
kindly_ask_env "BASE_URL"
|
|
kindly_ask_env "SECRET" do
|
|
warning "\"SECRET\" will be randomly generated as a fallback"
|
|
ENV["SECRET"] = SecureRandom.hex(64)
|
|
end
|
|
harshly_do env["SECRET"].size < 8 do
|
|
error "Your secret is NOT very secret, fix this (at least 8 hexadigits entropy)"
|
|
end
|
|
end.finish!
|
|
|
|
# Setup module variables
|
|
DB = Sequel.connect ENV["DB"]
|
|
BASE_URL = ENV["BASE_URL"] || "http://localhost:4567"
|
|
SECRET = ENV["SECRET"]
|
|
# CODE_VERSION = DB[:meta].first[:code_version]
|
|
# CODE_DATE = DB[:meta].first[:code_date]
|
|
|
|
Dir[File.join(__dir__, 'utils', '*.rb')].each { |file| require file }
|
|
Dir[File.join(__dir__, 'models', '*.rb')].each { |file| require file }
|
|
|
|
if __FILE__ == $0
|
|
require_relative "web"
|
|
class App
|
|
run!
|
|
end
|
|
end
|