Created
January 11, 2017 10:29
-
-
Save Yukaii/9ec2509b1ebad641ba75fcabdfbb24ac to your computer and use it in GitHub Desktop.
Node with pow from https://github.com/linjunpop/node-with-pow/blob/master/config.ru
This file contains hidden or 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
| require "net/http" | |
| class ProxyApp | |
| def call(env) | |
| begin | |
| request = Rack::Request.new(env) | |
| headers = {} | |
| env.each do |key, value| | |
| if key =~ /^http_(.*)/i | |
| headers[$1] = value | |
| end | |
| end | |
| http = Net::HTTP.new("localhost", 1337) | |
| http.start do |http| | |
| response = http.send_request(request.request_method, request.fullpath, request.body.read, headers) | |
| [response.code, response.to_hash, [response.body]] | |
| end | |
| rescue Errno::ECONNREFUSED | |
| [500, {}, ["Server is down, try $npm start"]] | |
| end | |
| end | |
| end | |
| run ProxyApp.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment