lib/pieces/server.rb in pieces-0.4.2 vs lib/pieces/server.rb in pieces-0.4.3
- old
+ new
@@ -1,7 +1,8 @@
require 'rack'
require 'listen'
+require 'sprockets'
module Pieces
class Server < Rack::Server
attr_reader :path
@@ -13,16 +14,24 @@
def start
Pieces::Listener.new(path: path).listen
super
end
+ def sprockets_env
+ Sprockets::Environment.new.tap do |env|
+ env.append_path 'app/assets/javascripts'
+ env.append_path 'app/assets/stylesheets'
+ end
+ end
+
def app
- files = files_to_serve(path)
+ urls = files_to_serve(path)
build_path = "#{path}/build"
Rack::Builder.app do
use Rack::Reloader
- use Rack::Static, urls: files, root: build_path, index: 'index.html'
+ use Rack::Static, urls: urls, root: build_path, index: 'index.html'
+ map('/assets') { run sprockets_env } unless defined? ::Rails
run Proc.new { |env| [404, {}, ['Not found']] }
end
end
private