Class: Staticd::App
- Inherits:
-
Object
- Object
- Staticd::App
- Defined in:
- lib/staticd/app.rb
Overview
Instance Method Summary collapse
-
#initialize(config) ⇒ App
constructor
Initialize the Staticd app.
-
#run ⇒ Object
Start the application.
Constructor Details
#initialize(config) ⇒ App
Initialize the Staticd app.
General configuration:
-
environment: the app environment (test, development or production)
-
domain: base to generate per app sub-domain
-
public_port: port used to generate application and endpoint url, (default to 80)
-
database: database url to store resources metadata
-
datastore: datastore url to store resources
-
host: host to listen to
-
port: port to listen to
API service configuration:
-
api: enable the API service
-
access_id: HMAC authentication access ID for the API service
-
secret_key: HMAC authentication secret key for the API service
HTTP service configuration:
-
http: enable the HTTP service
-
http_cache: folder where resources are cached
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/staticd/app.rb', line 42 def initialize(config) @config = config @config[:public_port] ||= "80" require_settings(:environment, :domain, :database, :datastore) env = @config[:environment] puts "Starting Staticd in #{env} environment." unless env == "test" display_current_config if env == "development" init_database init_datastore end |
Instance Method Details
#run ⇒ Object
Start the application.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/staticd/app.rb', line 56 def run require_settings(:host, :port) require_settings(:http_cache) if @config[:http] require_settings(:access_id, :secret_key) if @config[:api] routes = {} routes["/"] = build_http_service if @config[:http] routes["/api/#{Staticd::API::VERSION}"] = build_api_service if @config[:api] router = Rack::URLMap.new(routes) Rack::Server.start( Host: @config[:host], Port: @config[:port], app: router, environment: @config[:environment] ) end |