module Susanoo::CLI::Commands::Server
Provide the `server` command for project wide usage.
Public Instance Methods
server(platform = 'android')
click to toggle source
# File lib/susanoo/cli/project_interface/server.rb, line 14 def server(platform = 'android') port = options[:port] if options[:built] return not_built unless built? app = static_server_for platform else require File.join(project_root, 'config/routes') # Set global debug flag Susanoo::Project.debug = options[:debug] app = ROUTER end # Run the selected application to serve the project Rack::Server.start(app: app, server: :thin, Port: port, debug: options[:debug]) end
Private Instance Methods
built?()
click to toggle source
Does project is built?
# File lib/susanoo/cli/project_interface/server.rb, line 37 def built? return false unless File.directory? File.join(project_root, 'www') true end
not_built()
click to toggle source
# File lib/susanoo/cli/project_interface/server.rb, line 42 def not_built error "'www' directory is not present. Build you app first." end
static_server_for(platform)
click to toggle source
Return a `Rack` applciation which will serve the already built project under specific platform path
# File lib/susanoo/cli/project_interface/server.rb, line 48 def static_server_for(platform) require 'rack/rewrite' root = project_root app = Rack::Builder.new do use Rack::Rewrite do rewrite '/', "/#{platform}_asset/www" end map "/#{platform}_asset/www/" do run Rack::Directory.new File.join(root, 'www') end end end