forked from static-publisher/static-publisher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
40 lines (34 loc) · 1019 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'sinatra'
require 'json'
require 'yaml'
require_relative 'lib/admin/simple_database'
require_relative 'lib/admin/auth_helpers'
require_relative 'lib/admin/config_files'
helpers AuthHelpers
configure do
set :db, SimpleDatabase.new(ENV['MONGOLAB_URI'])
settings.db.create_if_empty(:user, name: 'admin', password: 'admin')
settings.db.create_if_empty(:config, ConfigFiles.seed)
set :schema, ConfigFiles.schema.to_json
set :form, ConfigFiles.form.to_json
`git config --global user.name "Static Publisher"` if `git config user.name`.empty?
`git config --global user.email "[email protected]"` if `git config user.email`.empty?
end
get '/admin' do
protected!
erb :admin
end
post '/user' do
protected!
settings.db.set(:user, params)
redirect '/admin'
end
post '/config' do
protected!
settings.db.set(:config, JSON.parse(request.body.read))
halt 200
end
post '*' do |path|
spawn("ruby #{File.expand_path('../bin/static_publisher.rb', __FILE__)} #{path}")
halt 200
end