28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/belphanior/servant/servant_config.rb', line 28
def self.registered(app)
app.set :servant_config_file, ServantConfigHelper::DEFAULT_CONFIG_PATH
app.set :servant_config_db, ServantConfigDb.new(
<<EOF
{
"ip":"127.0.0.1",
"port": "80"
}
EOF
)
app.get '/config' do
BelphaniorServantHelper.text_out_as_json(settings.servant_config_db.to_json)
end
app.get '/config/:name' do
[200, settings.servant_config_db.get(params[:name])]
end
app.post '/config/:name' do
old_value = settings.servant_config_db.get(params[:name])
begin
settings.servant_config_db.set(params[:name], request.body.read)
ServantConfigHelper.write_config_file(
settings.servant_config_file, settings.servant_config_db)
return [200, old_value]
rescue ServantConfigException => e
return [500, "Could not write config: #{e}"]
end
end
end
|