access env (logger, database) before first request
jsaak opened this issue · comments
jsaak commented
maybe i overlooked something, it is hard to believe i am the only one needing this feature
what i need is access to the environment (logger, database) when the server starts
is there a way currently?
or shall i implement it?
class Server < Goliath::API
def setup
p env
p @env
end
def initialize
p env
p @env
end
end
outputs nil-s
jsaak commented
found it: i probably need to write a plugin for that
https://github.com/postrank-labs/goliath/wiki/Plugins
require 'goliath'
require 'em-synchrony'
require 'em-synchrony/em-mongo'
require 'pp'
module Goliath
module Plugin
class Thing
def initialize(address, port, config, status, logger)
logger.info 'creating indexes'
config['mongo'].collection('collectionname').create_index [['name', EM::Mongo::ASCENDING]]
end
def run
end
end
end
end
class TestPlugin < Goliath::API
plugin Goliath::Plugin::Thing
def response
end
end
and in config/test_plugin.rb
environment(:development) do
config['mongo'] = EventMachine::Synchrony::ConnectionPool.new(size: 20) do
conn = EM::Mongo::Connection.new('localhost', 27017, 1, {:reconnect_in => 1})
conn.db('databasename')
end
end