Skip to content

Instantly share code, notes, and snippets.

@mrkn
Created August 4, 2009 07:53
Show Gist options
  • Save mrkn/161087 to your computer and use it in GitHub Desktop.
Save mrkn/161087 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# coding: utf-8
require 'webrick'
require 'Win32API'
require 'rubygems'
require 'rack'
require 'sinatra'
set :run, false
get '/' do
'Hello, Sinatra [<a href="/server/quit">quit</a>]'
end
Rack::Handler::WEBrick.run Sinatra::Application, :Port=>0 do |server|
trap :INT do
server.shutdown
end
get '/server/quit' do
server.stop
'sinatra_test is going to be shutdown...'
end
shell_execute = Win32API.new('shell32.dll', 'ShellExecuteA', %w(p p p p p i), 'i')
shell_execute.call(0, 'open', "http://localhost:#{server[:Port]}", 0, 0, 1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment