Skip to content

Instantly share code, notes, and snippets.

@luk3thomas
Created February 22, 2018 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luk3thomas/394a0fede12427b829e70c4a8422b41f to your computer and use it in GitHub Desktop.
Save luk3thomas/394a0fede12427b829e70c4a8422b41f to your computer and use it in GitHub Desktop.
Proxy to staging

Prereqs

  1. bundle install
  2. Copy your _appoptics_session cookie from staging.

Start the server

Start the server on port 9989

WEBPACK_PORT=4321 SESSION_COOKIE='_appoptics_session=[redacted]; path=/;' bundle exec rackup config.ru -p 9989
require 'rack-proxy'
abort "WEBPACK_PORT required" unless ENV['WEBPACK_PORT']
abort "SESSION_COOKIE required" unless ENV['SESSION_COOKIE']
class ProxyAppoptics < Rack::Proxy
def rewrite_env(env)
env['HTTP_COOKIE'] = ENV['SESSION_COOKIE']
env
end
def rewrite_response(resp)
status, headers, response = resp
body = response.to_s
.gsub(%r{https://cdn.appoptics.com/assets/(.*)-[A-z0-9]+\.js}, "http://0.0.0.0:#{ENV['WEBPACK_PORT']}/assets/\\1.js")
.gsub('environment: "staging"', 'environment: "dev", instrument: false')
[status, headers, [body]]
end
end
use ProxyAppoptics, {backend: "https://my-stg.appoptics.com"}
run proc {|env| [404, {}, ["not found"]]}
source "https://rubygems.org"
gem "rack"
gem "rack-proxy"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment