Skip to content

Instantly share code, notes, and snippets.

@bezhermoso
Created March 15, 2016 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bezhermoso/ffe79962000c3d50ad88 to your computer and use it in GitHub Desktop.
Save bezhermoso/ffe79962000c3d50ad88 to your computer and use it in GitHub Desktop.
module Sinkdown
class Server
def initialize
Faye::WebSocket.load_adapter 'thin'
@thin = Rack::Handler.get 'thin'
end
def serve(site)
app = Rack::Builder.new do
use Sinkdown::Middleware::Reload,
:site => site
use Rack::Cors do
allow do
origins '*'
resource '/',
:methods => [:get, :post, :delete, :put, :options, :head]
end
end
use Faye::RackAdapter,
:mount => '/faye',
:timeout => 25
# Serve Markdown -> HTML files
use Rack::Static,
:urls => ['/html'],
:root => site.config[:sinkdown_dir],
:index => 'index.html'
use Rack::Static,
:urls => ['/css', '/js'],
:root => File.dirname(__FILE__) + '/assets'
use Sinkdown::Middleware::Api,
:site => site
run Sinkdown::Middleware::RedirectHome
end
@thin.run app, :Port => site.config[:port]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment