node -v): v11.6.0npm -v): 6.5.0When I run
npm run hot
or
yarn run hot
I get this in the console
app.js:22362 Invalid Host/Origin header
error @ app.js:22362
onmessage @ app.js:22632
EventTarget.dispatchEvent @ app.js:3691
(anonymous) @ app.js:4408
SockJS._transportMessage @ app.js:4406
EventEmitter.emit @ app.js:3607
WebSocketTransport.ws.onmessage @ app.js:6482
app.js:22365 [WDS] Disconnected!
close @ app.js:22365
onclose @ app.js:22608
EventTarget.dispatchEvent @ app.js:3691
(anonymous) @ app.js:4490
setTimeout (async)
SockJS._close @ app.js:4478
SockJS._transportMessage @ app.js:4418
EventEmitter.emit @ app.js:3607
WebSocketTransport.ws.onmessage
New install of Laravel
app.js
import Vue from 'vue';
Vue.component('sample-component', require('./components/sample-component.vue').default);
const app = new Vue({
el: '#app'
});
sample-component.vue
<script>
export default {
}
</script>
<template>
<div>
Sample Fault Component
</div>
</template>
welcome.blade.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>Sample Fault Page</title>
</head>
<body>
<div id="app">
<sample-component />
</div>
{{--
This works if I run yarn run dev
<script src="/js/app.js"></script>
--}}
<script src="http://localhost:8080/js/app.js"></script>
</body>
</html>
Add --disable-host-check parameter to hot script in package.json
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
Read more
https://webpack.js.org/configuration/dev-server/#devserver-disablehostcheck
Add
--disable-host-checkparameter tohotscript in package.json"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",Read more
https://webpack.js.org/configuration/dev-server/#devserver-disablehostcheck
Thanks. I can confirm this works and as hot is only used in development the security issues are not relevant.
It looks as though explicitly configuring the HMR host is another pretty simple solution to this:
mix.options({
hmrOptions: {
host: 'your.test.domain'
}
});
Having said that, if you need to support multiple devs who may be using different test domains it鈥檚 going to be simpler just to disable the check outright.
As I can't ever see where people would run hot in production
--disable-host-check
should be there by default so that this works out of the box.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Add
--disable-host-checkparameter tohotscript in package.jsonRead more
https://webpack.js.org/configuration/dev-server/#devserver-disablehostcheck