duan0417 2018-06-18 19:16
浏览 412

无法从Web应用程序连接到localhost:3000

I'm working on some boilerplate code to get a VueJS frontend working with a Go-powered backend (using gorilla/mux for a router):

Currently, I seem to have everything working for the most part. I'm serving a static HTML file via Go and rendering Vue stuff with it that's being bundled with webpack (webpack-dev-server currently, not a physical bundle), and I'm having a weird issue:

In my browser, Firefox keeps telling me the following:

Firefox can’t establish a connection to the server at http://localhost:3000/__webpack_hmr.

Yet, when I change Vue components and save them, they're auto-refreshing in the browser as I would expect. I'm really confused, I guess, I don't know why this is happening.

I've tried changing the port that my Go server operates on, and it always seems to fail connection at http://localhost:<Go Server Port>/__webpack_hmr.

Any thoughts? Maybe there's a step I'm missing or the setup is more complicated than I thought it was.

Do I need to be running an Express server and using the webpack-based Middleware to fix this error? If so, that sounds silly if I'm using Go for the backend (why would I run two servers?). Am I doing something wrong?

As for the Go side of things, I've tried both running the Go server on a different port and having the webpack server run on different ports and such, but it always fails to connect at http://localhost:<Go Server Port>/__webpack_hmr.

Maybe this is more complicated to set up than I thought it was, or since it seems to be "working", I can safely ignore this error? I dunno.

  • 写回答

2条回答 默认 最新

  • duankuiyuant3940 2018-06-18 20:45
    关注

    Remove 'webpack-hot-middleware/client' from your webpack config and any references in your codebase. This is only used for hot reloading, so it's safe to remove it.

    Since you need hot reloading, you should use: https://github.com/go-webpack/webpack

    This module allows proper integration with webpack, with support for proper assets reloading in development and asset hashes for production caching.

    However they only show examples using Gin and Iris, so you may need to open an issue with them for an example based on purely net/http (assuming that's what you're using).

    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?