Skip to content

Instantly share code, notes, and snippets.

@timothypage
Last active December 25, 2021 10:36
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save timothypage/cc80e8f8db1b0b7eb0c81e8317a536ec to your computer and use it in GitHub Desktop.
Quick hack to passthrough sinatra to webpack-dev-server for awesome client hot reloading plus live api endpoints
#\ -s puma -p 4567
# require './server'
require './server'
require 'sidekiq'
require './config/initializers/sidekiq'
require 'sidekiq/web'
if ENV["RACK_ENV"] == "production"
run Rack::URLMap.new('/' => Sinatra::Application, '/sidekiq' => Sidekiq::Web)
else
require 'rack-proxy'
class AppProxy < Rack::Proxy
def rewrite_env(env)
env["HTTP_HOST"] = "localhost:8080"
env
end
end
run Rack::URLMap.new(
'/sidekiq' => Sidekiq::Web,
'/api' => Sinatra::Application,
'/' => AppProxy.new
)
end
source "https://rubygems.org"
gem "rack-proxy"
gem "sidekiq"
gem "sinatra"
gem "sinatra-contrib"
gem "py"
unless ENV["RACK_ENV"] == "production"
require 'pry'
unless ENV["NOPACK"] == "true"
pid = Process.spawn('./node_modules/.bin/webpack-dev-server')
Process.detach(pid)
puts "webpack dev server pid: #{pid}"
end
end
require 'sinatra'
require 'sinatra/json'
# config.ru adds /api
get '/projects'
projects = []
json projects
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment