Skip to content

Commit

Permalink
WIP: Refs #21312 - add webpack url with hostname csp
Browse files Browse the repository at this point in the history
  • Loading branch information
Avi Sharvit committed Dec 26, 2018
1 parent 0a18082 commit b563a99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 12 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,12 @@ def parameter_filter_context
end

def allow_webpack
webpack_csp = { script_src: [webpack_server], connect_src: [webpack_server],
style_src: [webpack_server], img_src: [webpack_server] }
webpack_urls = [webpack_server]

webpack_csp = {
script_src: webpack_urls, connect_src: webpack_urls,
style_src: webpack_urls, img_src: webpack_urls
}

append_content_security_policy_directives(webpack_csp)
end
Expand All @@ -393,6 +397,12 @@ def webpack_server
@dev_server ||= "#{request.protocol}#{request.host}:#{port}"
end

# def webpack_server_hostname
# port = Rails.configuration.webpack.dev_server.port
# hostname = Socket.gethostname
# @dev_server ||= "#{request.protocol}#{hostname}:#{port}"
# end

class << self
def parameter_filter_context
Foreman::ParameterFilter::Context.new(:ui, controller_name, nil)
Expand Down
7 changes: 5 additions & 2 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ const devServerConfig = () => {
throw result.error;
}

const host = args.host || process.env.BIND || 'localhost';
const publicHost = host === 'localhost' ? 'localhost' : args.host || os.hostname();

return {
port: args.port || '3808',
host: args.host || process.env.BIND || 'localhost',
publicHost: removePort(args.public) || args.host || os.hostname(),
host,
publicHost,
protocol: args.https ? 'https' : 'http',
}
}
Expand Down

0 comments on commit b563a99

Please sign in to comment.