Sha256: ec445168e7e41da43e21dcbac6d7bd1858edbab06839382bb1ba0313081d77fe

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby

require 'colorize'
require 'optparse'

require_relative '../lib/nephos-server/bin-helpers'
require_relative '../lib/nephos-server/version'

class RoutingError < StandardError; end

begin
  opts = OptionParser.new do |opts|
    opts.banner = "Usage<#{Nephos::VERSION}>: nephos-server <options>"

    $server_port = ENV["SERVER_PORT"] || 8080
    opts.on("-p=nb", "--port=nb", "Port to listen") do |port|
      $server_port = Integer(port)
    end

    $server_host = ENV["SERVER_HOST"] || "0.0.0.0"
    opts.on("-h=listen", "--host=listen", "Listen on the network") do |host|
      $server_host = host
    end

    $server_env = ENV["ENVIRONMENT"] || "development"
    opts.on("-e=env", "--env=env", "Environment") do |env|
      $server_env = env
    end

    opts.on("--debug", "Enable debugging mode") do
      $debug = true
    end

    opts.on("--test", "Enable testing mode (for nephos developpers)") do
      $test = true
    end

  end.parse!

  Nephos.env = $server_env

  Dir.chdir(opts[0]) if not opts.empty?

  if $test
    require_relative "../lib/nephos-server"
  else
    require 'nephos-server'
  end

  if not $test and
    (not File.exists? "Gemfile.lock" or
     not File.read("Gemfile.lock").split.index("nephos-server"))
    raise InvalidApplication
  end

  puts "Running Nephos::Server version #{Nephos::VERSION} (#{Nephos.env})"
  Nephos::Server.start($server_port, $server_host)

rescue RoutingError => err
  puts "Routing Error: Check out the documentation and `routes.rb` file.".yellow
  puts "#{err.class}: #{err.message}".red

rescue => err
  puts "#{err.class}: #{err.message}".red
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nephos-server-0.5.4 bin/nephos-server