webpack: Disable host check for webpack-dev-server.

Webpack dev server by default does host checking for requests. so
in dev enviorment if the the request came for zulipdev.com it would not
send js files which caused dev envoirment to not work.
This commit is contained in:
Priyank Patel 2018-04-24 13:27:15 +00:00 committed by Tim Abbott
parent 62fb139af7
commit bc454bab88
2 changed files with 12 additions and 3 deletions

View File

@ -166,6 +166,10 @@ else:
webpack_cmd = ['./tools/webpack', '--watch', '--port', str(webpack_port)] webpack_cmd = ['./tools/webpack', '--watch', '--port', str(webpack_port)]
if options.minify: if options.minify:
webpack_cmd.append('--minify') webpack_cmd.append('--minify')
if options.interface is None:
# If interface is None and we're listening on all ports, we also need
# to disable the webpack host check so that webpack will serve assets.
webpack_cmd.append('--disable-host-check')
if options.interface: if options.interface:
webpack_cmd += ["--host", options.interface] webpack_cmd += ["--host", options.interface]
else: else:

View File

@ -25,13 +25,15 @@ def run():
['--config', 'tools/webpack.config.ts', '-p'] + ['--config', 'tools/webpack.config.ts', '-p'] +
['--env', 'production']) ['--env', 'production'])
def run_watch(host, port, minify): def run_watch(host, port, minify, disable_host_check):
# type: (str, str, bool) -> None # type: (str, str, bool, bool) -> None
"""watches and rebuilds on changes, serving files from memory via webpack-dev-server""" """watches and rebuilds on changes, serving files from memory via webpack-dev-server"""
webpack_args = ['node', 'node_modules/.bin/webpack-dev-server'] webpack_args = ['node', 'node_modules/.bin/webpack-dev-server']
webpack_args += ['--config', 'tools/webpack.config.ts', '--port', port, "--host", host] webpack_args += ['--config', 'tools/webpack.config.ts', '--port', port, "--host", host]
if minify: if minify:
webpack_args.append('--optimize-minimize') webpack_args.append('--optimize-minimize')
if disable_host_check:
webpack_args.append('--disable-host-check')
subprocess.Popen(webpack_args) subprocess.Popen(webpack_args)
def run_test(): def run_test():
@ -72,11 +74,14 @@ parser.add_argument('--port',
parser.add_argument('--minify', parser.add_argument('--minify',
action='store_true', dest='minify', default=False, action='store_true', dest='minify', default=False,
help='Minify and optimize the assets (for development)') help='Minify and optimize the assets (for development)')
parser.add_argument('--disable-host-check',
action='store_true', dest='disable_host_check', default=None,
help='Disable host check for webpack-dev-server')
args = parser.parse_args() args = parser.parse_args()
if args.test: if args.test:
run_test() run_test()
elif args.watch: elif args.watch:
run_watch(args.host, args.port, args.minify) run_watch(args.host, args.port, args.minify, args.disable_host_check)
else: else:
run() run()