doutuo7156 2017-11-13 09:55 采纳率: 100%
浏览 43
已采纳

找不到捆绑的文件

I am using Golang (Echo) for my backend and React for my frontend. When I bundle my code using webpack, the file is created; however, I am getting an error in my console when I go to localhost:3000 stating the bundle file cannot be found. This is the exact error message: GET http://localhost:3000/build/app.bundle.js net::ERR_ABORTED.

Here is my server:

func main() {
    env.SetEnvVars()

    e := echo.New()
    e.File("/", "server/static/index.html")

    e.Logger.Fatal(e.Start(os.Getenv("PORT")))
}

Here is my webpack.config.js file:

module.exports = {
  entry: './client/main.jsx',
  output: {
    path: path.resolve(__dirname, 'server/static/build'),
    filename: 'app.bundle.js'
  },
  ...

And the script tag in my index.html file is:

<script src="./build/app.bundle.js"></script>

The directory path regarding these files is currently:

/
  server/
    main.go
    static/
      index.html
      build/
        app.bundle.js

Any help would be appreciated!

  • 写回答

1条回答 默认 最新

  • dongxie8906 2017-11-13 10:36
    关注

    The echo server you've set up only serves one single path, the root path ("/"), by rendering the contents of the index.html file. Because you haven't set up any other handlers for that server, any request to a path other than the root will result in 404, including those requests made from the index page via script and link tags, e.g.; <script src="./build/app.bundle.js"></script>.

    To be able to serve a request to a path like "/static/build/app.bundle.js" for example you need to tell the server how to do that by registering a new handler.

    With the echo server you can use its Static method to do that.

    e.Static("/static", "static")
    

    Please keep in mind that the links you use in html tags, the location of the corresponding files on your machine, and the location from where you launched your app matters if you use relative paths like ./build/app.bundle.js, and because of that the two arguments to e.Static may need to be somewhat different from the example here.

    Here's a bit more info.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?