-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix "EOFError error" when using webpack dev server over HTTPS #113
Merged
jamesmartin
merged 4 commits into
jamesmartin:master
from
kylefox:ssl-webpack-dev-server
Feb 23, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
78f7bf7
Support SSL with webpack dev server
kylefox 0477fec
break network request and tempfile construction into different privat…
kylefox 56989a8
better error handling/messages when fetching from webpack-dev-server
kylefox d232345
make WebpackAssetFinder#pathname do less
kylefox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,32 +6,45 @@ def self.find_asset(filename) | |
|
||
def initialize(filename) | ||
@filename = filename | ||
@asset_path = Webpacker.manifest.lookup(@filename) | ||
end | ||
|
||
def pathname | ||
file_path = Webpacker.instance.manifest.lookup(@filename) | ||
return unless file_path | ||
return if @asset_path.blank? | ||
|
||
if Webpacker.dev_server.running? | ||
asset = Net::HTTP.get(Webpacker.dev_server.host, file_path, Webpacker.dev_server.port) | ||
|
||
begin | ||
Tempfile.new(file_path).tap do |file| | ||
file.binmode | ||
file.write(asset) | ||
file.rewind | ||
end | ||
rescue StandardError => e | ||
Rails.logger.error "Error creating tempfile: #{e}" | ||
raise | ||
end | ||
dev_server_asset(@asset_path) | ||
elsif Webpacker.config.public_path.present? | ||
File.join(Webpacker.config.public_path, @asset_path) | ||
end | ||
end | ||
|
||
private | ||
|
||
else | ||
public_path = Webpacker.config.public_path | ||
return unless public_path | ||
def dev_server_asset(file_path) | ||
asset = fetch_from_dev_server(file_path) | ||
|
||
File.join(public_path, file_path) | ||
begin | ||
Tempfile.new(file_path).tap do |file| | ||
file.binmode | ||
file.write(asset) | ||
file.rewind | ||
end | ||
rescue StandardError => e | ||
Rails.logger.error "[inline_svg] Error creating tempfile for #{@filename}: #{e}" | ||
raise | ||
end | ||
end | ||
|
||
def fetch_from_dev_server(file_path) | ||
http = Net::HTTP.new(Webpacker.dev_server.host, Webpacker.dev_server.port) | ||
http.use_ssl = Webpacker.dev_server.https? | ||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
http.request(Net::HTTP::Get.new(file_path)).body | ||
rescue StandardError => e | ||
Rails.logger.error "[inline_svg] Error fetching #{@filename} from webpack-dev-server: #{e}" | ||
raise | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can get rid of this check. I can't think of a scenario where an application using webpacker would not have
Webpacker.config.public_path
configured. 🤔