-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add dev server config class and setup proxy #637
Conversation
Add options for ssl and set publicPath to only pack output path
Add dev_server config
Move dev-server to defaults
Fix typos Delete if path exists
1acace9
to
b83b2ad
Compare
Remove extra if
ce1ad37
to
40a2d04
Compare
There is one extra bit of change here i.e. renaming So I have setup the RAILS.env to be test to avoid any discrepancy: module TestApp
class Application < ::Rails::Application
config.root = File.join(File.dirname(__FILE__), "test_app")
config.eager_load = true
::Rails.env = ENV["RAILS_ENV"] = "test"
end
end and renamed all test_app folders from |
key: readFileSync(devServer.ssl_key_path), | ||
cert: readFileSync(devServer.ssl_cert_path) | ||
} | ||
} |
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.
When do we ever need to bother with HTTPS in development?
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.
@dhh There were some issues filed where people are using HTTPS for development, mainly for cases where they are interacting with API's that is hosted on HTTPS
Links?
…On Sat, Aug 12, 2017 at 2:03 PM, Gaurav Tiwari ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In lib/install/config/webpack/development.js
<#637 (comment)>:
> const sharedConfig = require('./shared.js')
const { settings, output } = require('./configuration.js')
+const { dev_server: devServer } = settings
+let https = devServer.https
+
+// Set ssl key and certificates if supplied
+if (devServer.ssl_key_path && devServer.ssl_cert_path) {
+ https = {
+ key: readFileSync(devServer.ssl_key_path),
+ cert: readFileSync(devServer.ssl_cert_path)
+ }
+}
@dhh <https://github.com/dhh> There were some issues filed where people
are using HTTPS for development, mainly for cases where they are
interacting with API's that is hosted on HTTPS
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#637 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAKtSV_zs7FhmrhyGctSSlNyyWVOPzyks5sXfb5gaJpZM4O1Yxc>
.
|
@dhh Should we move the proxy middleware to middlewares folder, guess we gonna have one more middleware for |
What do we need for cache-control? |
Don't need to advertise that so loudly.
Ah yes. Let's do a separate PR for that. |
Yepp 👍 |
Actually, if we just use -hash in dev as well, we shouldn't need to explicitly set any headers? But not sure how that'll combine with the dev server. |
Yeah that will work 👍 I doubt this is a problem when using dev-server because it takes care of settings cache-control. I guess this is happening mainly with watcher, where assets are being served by Rails server and getting cached but -hash can totally fix it |
For SSL, we should double down on the reproxy setup. The dev server should not need to know about this. Just like people use nginx to terminate SSL before talking to a puma server. |
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.
@gauravtiwari I have a few questions for you.
@@ -5,7 +5,8 @@ module.exports = { | |||
use: [{ | |||
loader: 'file-loader', | |||
options: { | |||
publicPath: output.publicPath, | |||
// Set publicPath with ASSET_HOST env if available so internal assets can use CDN |
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.
@gauravtiwari can you explain this comment a bit more.
@@ -24,7 +24,8 @@ function formatPublicPath(host = '', path = '') { | |||
|
|||
const output = { | |||
path: resolve('public', settings.public_output_path), | |||
publicPath: formatPublicPath(env.ASSET_HOST, settings.public_output_path) | |||
publicPath: `/${settings.public_output_path}/`.replace(/([^:]\/)\/+/g, '$1'), |
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.
@gauravtiwari Any chance that you can provide some examples and maybe comments on what's going on here with the formatting of the publicPath.
Since publicPathWithHost uses a function, how about extracting the plain publicPath into a function as well.
Maybe it's me, but doing a string interpolation that feeds into a regexp replace could be a bit less terse for more readability.
I get that you take:
public_output_path = "packs"
and get
public_path ==> "/packs/"
But I'm not following on why you'd be doing something like take "abc//packs/" with a double // in the string, you'd change the double slash to a single slash, and you won't change the protocol.
Is not having slashes in the in the public_output_path an error that should just be reported?
Maybe there's some information missing from the README.md on what you want for the public_output_path
?
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.
On line 32 below, can you confirm that you're using the adding of the source_path to make non-JS asset inclusion easier? Or are there other reasons?
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.
@justin808 I am going to push some cleanup for this whole webpack part in another PR. Basically, the idea was to not end up with //
if public_output_path
is set to ''
i.e. the assets will be outputted at root. Since we are now using proxy, there is no host for publicPath
except for internal assets like fonts or images, that's what publicPathWithHost
is used for.
On line 32 below, can you confirm that you're using the adding of the source_path to make non-JS asset inclusion easier? Or are there other reasons?
Yes, that's just adding source path to webpack module resolver.
class Webpacker::DevServerProxy < Rack::Proxy | ||
def rewrite_response(response) | ||
status, headers, body = response | ||
headers.delete "transfer-encoding" |
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.
Hi @gauravtiwari do you by any chance remember why you needed to delete the Transfer-Encoding header? Maybe something to do with preventing Gzipping?
Doing so breaks chunked streaming as per #2196 (review)
Currently my PR conditionally deletes the header under the assumption that in some cases it does need deleting, but as suggested it would be even better to get rid of the line if not needed :)
This PR adds a few things related to webpack-dev-server:
Move dev-server-settings to defaults so it's transparently available in all environments
The host info has been removed from manifest.json, now looks like this: