Last active
December 25, 2021 10:36
Star
You must be signed in to star a gist
Quick hack to passthrough sinatra to webpack-dev-server for awesome client hot reloading plus live api endpoints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#\ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "rack-proxy" | |
gem "sidekiq" | |
gem "sinatra" | |
gem "sinatra-contrib" | |
gem "py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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