Recently learning Ethereum, with truffle webpack encounter a problem, is to start the service can use localhost:8080 access, but can not use ip:8080 access. In this way, the other computer will not be able to access its own applications.
Native ip:219.216.65.127
I did a little experiment, nodejs+express, and I started the application with node, I can access it with localhost:3000, I can access it with 219.216.65.127:3000, and another computer can access it. So I'm thinking about the problem of not webpack configuration.
Search for someone else's solution on the Web: npm Run Dev--host "0.0.0.0"
Unfortunately, I did not succeed (I do not know where there is a problem, trouble who knows to help me leave a message, thank you)
The results are as follows:
$ npm Run dev--host 219.216.65.127 > truffle-init-webpack@0.0.2 dev/home/hepu/desktop/test/test > Webpack-dev-ser Ver "219.216.65.127" Project is running at Http://localhost:8080/webpack output is served from/hash:2e535af56b1ecc259 B4A version:webpack 2.7.0 time:2047ms Asset Size Chunks Chunk Names app.js 1.35 MB 0 [emitted] [big] main index.html 925 bytes [emitted] chunk {0} app.js (main) 1.32 MB [ent [Rendered] [ry]./~/web3/index.js 193 bytes {0} [built] [+]./app/javascripts/app.js 3.64 KB {0} [built] [87 ] (webpack)-dev-server/client?http://localhost:8080 5.83 KB {0} [built]./build/contracts/metacoin.json 2.62 KB {0
} [built] [127]./~/loglevel/lib/loglevel.js 6.74 KB {0} [built] [161]./~/strip-ansi/index.js 161 bytes {0} [built] [163]./~/style-loader/addstyles.js 6.91 KB {0} [built] [164]./app/stylesheets/app.css 905 bytes {0} [built] [171]. /~/truffle-contract/indeX.js 2.64 KB {0} [built] [206]./~/url/url.js 23.3 KB {0} [built] [241] (Webpack)-dev-server/client/overlay.js 3.6 kb {0} [built] [242] (webpack)-dev-server/client/socket.js 856 bytes {0} [built] [244] (webpack)/hot nonrecursive ^\.\/lo g$ bytes {0} [built] [245] (webpack)/hot/emitter.js bytes {0} [built] [247] multi (webpack)-dev-server/client?h ttp://localhost:8080./app/javascripts/app.js 219.216.65.127 bytes {0} [built] + 233 hidden modules ERROR in mult I (Webpack)-dev-server/client?http://localhost:8080./app/javascripts/app.js 219.216.65.127 Module not found:error: Can ' t resolve ' 219.216.65.127 ' in '/home/hepu/desktop/test/test ' @ multi (webpack)-dev-server/client?http://localhost : 8080./app/javascripts/app.js 219.216.65.127 webpack:failed to compile.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Method 1: According to the above error, I found the webpack-dev-server/.bin/webpack-dev-server.js file in the Node_modules directory, the field in the Yargs.options
"Host": {
Type: "string",
//default: "localhost",
default: "219.216.65.127", //New
describe: " The HOSTNAME/IP address the server would bind to ",
Group:connection_group
}
1 2 3 4 5 6 7
Changing the default IP address to the cost machine IP, restarting the application, is now accessible with 219.216.65.127:8080. But it can't be accessed with localhost:8080.
Method 2:https://github.com/webpack/webpack-dev-server/issues/147
In the above link found a solution, is to start the service directly with Node_modules/.bin/webpack-dev-server–hot–host 219.216.65.127, without npm run dev.
Startup success
~/desktop/test/test$ node_modules/.bin/webpack-dev-server--hot--host 219.216.65.127 Project is running at/HTTP 219.216.65.127:8080/webpack output is served from/hash:1120d8dcc38ac654dcf2 version:webpack 2.7.0 time:2038ms A Sset Size Chunks Chunk Names app.js 1.38 MB 0 [emitted] [big] main index.html 9 [emitted] Chunk {0} app.js (main) 1.32 MB [Entry] [rendered] [bytes]./~/web3/index.js 193 B ytes {0} [built] [Webpack]/hot/emitter.js bytes {0} [built] [+]./app/javascripts/app.js 3.64 KB {0} [built ] [Webpack] (-dev-server/client?http://219.216.65.127:8080 5.83 kB {0} [built] [all] (webpack)/hot/dev-server.js 1 . KB {0} [built] [/build/contracts/metacoin.json]. 2.62 KB {0} [built] [129]./~/loglevel/lib/loglevel.js 6.74 K B {0} [built] [163]./~/strip-ansi/index.js 161 bytes {0} [built] [166]./app/stylesheets/app.css 905 bytes {0} [built ] [173]./~/truffle-contract/Index.js 2.64 KB {0} [built] [208]./~/url/url.js 23.3 KB {0} [built] [244] (Webpack)-dev-server/client/socket.js 856 bytes {0} [built] [246] (Webpack)/hot nonrecursive ^\.\/log$ bytes {0} [built] [247] (Webpack)/hot/log-apply-resul T.js 1.02 KB {0} [built] [249] multi (webpack)-dev-server/client?http://219.216.65.127:8080 webpack/hot/dev-server./ap P/javascripts/app.js bytes {0} [built] + 235 hidden modules webpack:compiled successfully.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
As with Method 1, it can only be accessed with ip+port and cannot be accessed with Localhost+port.
Transferred from: https://blog.csdn.net/yooliee/article/details/76283872