Added rake task to start server in a more production-ready manner using Puma; move config values to config directory

This commit is contained in:
Gregory Ballantine 2023-03-09 23:22:18 -05:00
parent 39ce636c0a
commit 0927a00960
7 changed files with 22 additions and 8 deletions

2
.gitignore vendored
View File

@ -60,7 +60,7 @@ build-iPhoneSimulator/
data/stgm.db
# Local configuration
data/config.yaml
config/config.yaml
# Node modules for Grunt.js
node_modules/

View File

@ -15,7 +15,11 @@ namespace :db do
end
namespace :server do
task :dev do
task :start do
system("bundle exec puma -C config/puma.rb")
end
task :reload do
%x{guard}
end
end

View File

@ -2,7 +2,7 @@ require 'yaml'
class Config
DEFAULT_CONFIG = 'data/defaults.yaml'
DEFAULT_CONFIG = 'config/defaults.yaml'
def initialize(config_path)
@data = YAML::load_file(DEFAULT_CONFIG)

View File

@ -1,3 +1,7 @@
# Load application config
require_relative 'app/config.rb'
$conf = Config.new(File.join(__dir__, 'config/config.yaml'))
# Load Sinatra server
require_relative './server.rb'

View File

@ -1,6 +1,10 @@
stgm:
base_directory: '/srv/videos'
server:
address: '127.0.0.1'
port: 4567
database:
adapter: 'sqlite'
database: 'data/stgm.db'

6
config/puma.rb Normal file
View File

@ -0,0 +1,6 @@
# Load application config
require './app/config.rb'
$conf = Config.new(File.join(__dir__, 'config/config.yaml'))
bind_address = "tcp://#{$conf.get('server.address')}:#{$conf.get('server.port')}"
bind bind_address

View File

@ -3,11 +3,6 @@ require 'sequel'
require 'sqlite3'
require 'sinatra/base'
require_relative 'app/config.rb'
# Load configuration file
$conf = Config.new(File.join(__dir__, 'data/config.yaml'))
# Load the Sequel timestamps plugin
Sequel::Model.plugin :timestamps
# Initialize Sequel gem for database actions
@ -48,4 +43,5 @@ class StageManager < Sinatra::Base
end
end
# Load controllers
Dir.glob('./app/routes/*.rb').each { |f| require f }