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 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误