-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dev server config class and setup proxy (#637)
* Add rack proxy Add options for ssl and set publicPath to only pack output path * Setup dev_server class Add dev_server config * Add and mount the dev_server proxy Move dev-server to defaults * Add tests Move to private Fix paths Update path names * Update changelog * Update changelog Fix typos Delete if path exists * Fix test env and update tests * Only add proxy in development Remove extra if * Nix extra CR * Move skipping compile on manifest lookups when dev server is running to manifest * Give proxy middleware its own initializer * Rely on @javan's fix instead of changing all these * Remove needless local variable * Fix compile predicate check * Nix dealing with HTTPS in development * Only proxy to dev server if its running * Better grouping * Nix need for config to return anything but full paths * Supply host_with_port * Only needed to delete this for HTTPS * Rare occurrence to run dev server in production Don't need to advertise that so loudly. * Not needed * Not needed * Not needed * Update documentation to our new proxy approach * Fix rubocop offenses
- Loading branch information
1 parent
acd81f5
commit 68b9f08
Showing
18 changed files
with
144 additions
and
48 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Webpacker::DevServer | ||
delegate :config, to: :@webpacker | ||
|
||
def initialize(webpacker) | ||
@webpacker = webpacker | ||
end | ||
|
||
def running? | ||
Socket.tcp(host, port, connect_timeout: 1).close | ||
true | ||
rescue Errno::ECONNREFUSED, NoMethodError | ||
false | ||
end | ||
|
||
def host | ||
fetch(:host) | ||
end | ||
|
||
def port | ||
fetch(:port) | ||
end | ||
|
||
def host_with_port | ||
"#{host}:#{port}" | ||
end | ||
|
||
private | ||
def fetch(key) | ||
config.dev_server.fetch(key, defaults[key]) | ||
end | ||
|
||
def defaults | ||
config.send(:defaults)[:dev_server] | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "rack/proxy" | ||
|
||
class Webpacker::DevServerProxy < Rack::Proxy | ||
def rewrite_response(response) | ||
status, headers, body = response | ||
headers.delete "transfer-encoding" | ||
response | ||
end | ||
|
||
def perform_request(env) | ||
if env["PATH_INFO"] =~ /#{public_output_uri_path}/ && Webpacker.dev_server.running? | ||
env["HTTP_HOST"] = Webpacker.dev_server.host_with_port | ||
super(env) | ||
else | ||
@app.call(env) | ||
end | ||
end | ||
|
||
private | ||
def public_output_uri_path | ||
Webpacker.config.public_output_path.relative_path_from(Webpacker.config.public_path) | ||
end | ||
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require "webpacker_test_helper" | ||
|
||
class DevServerTest < Minitest::Test | ||
def test_host | ||
assert_equal "localhost", Webpacker.dev_server.host | ||
end | ||
|
||
def test_port | ||
assert_equal Webpacker.dev_server.port, 3035 | ||
end | ||
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