将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

huangapple go评论91阅读模式
英文:

404 (Not Found) errors when converting a web app into Lorca desktop app

问题

背景

https://threejs.org/editor/ 是一个网页应用程序,其源代码作为 three.js 仓库的一部分:

https://github.com/mrdoob/three.js/tree/master/editor

我正在尝试使用 Lorca 将上述网页应用程序创建为桌面应用程序版本。

第一种方法

根据这里的建议,我使用 Lorca 的 计数器示例 作为基础。我将计数器示例复制到以下位置:

/home/m3/go/src/lorca-3d-editor

然后,我在以下位置克隆了 three.js:

/home/m3/repos/three.js

three.js 编辑器将位于:

/home/m3/repos/three.js/editor

现在,我将 Lorca 计数器示例的源代码更改如下,注意 http.Dir() 设置了绝对路径:

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		log.Fatal(err)
	}
	defer ln.Close()
	go http.Serve(ln, http.FileServer(http.Dir("/home/m3/repos/three.js/editor")))
	ui.Load(fmt.Sprintf("http://%s", ln.Addr()))

提交的差异如下:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

但是我遇到了这些 404 (Not Found) 错误:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

第二种方法

我在这里保留了 Lorca 计数器示例的副本:

/home/m3/go/src/lorca-3d-editor

然后,我将整个 three.js 源代码复制到这里:

/home/m3/go/src/lorca-3d-editor/three.js

因此,网页应用程序的源代码将位于:

/home/m3/go/src/lorca-3d-editor/three.js/editor

现在,我将 Lorca 计数器示例的源代码更改如下,注意 http.Dir("three.js/editor") 设置了相对路径:

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		log.Fatal(err)
	}
	defer ln.Close()
	go http.Serve(ln, http.FileServer(http.Dir("three.js/editor")))
	ui.Load(fmt.Sprintf("http://%s", ln.Addr()))

现在我又遇到了一些 404 (Not Found) 错误:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

可能的问题

可能的问题是,three.js/editor 中的网页应用程序引用了 three.js 仓库中的一些文件。但是,当在 Go 的 HTTP 服务器中提供 three.js/editor 中的静态文件时,HTTP 服务器无法找到 three.js 仓库中散布在 three.js/editorthree.js 仓库本身的内容中引用的所有外部文件。如何解决这样的问题是最佳实践?

英文:

Background

There is a web app of https://threejs.org/editor/ with its source code as part of three.js repository:

https://github.com/mrdoob/three.js/tree/master/editor

I'm trying to use the above with Lorca to create a desktop app version of the web app.

First approach

As sugggested here, I use the Lorca counter example as a base. I copy the counter example in this location:

/home/m3/go/src/lorca-3d-editor

Then I clone the three.js at this location:

/home/m3/repos/three.js

The three.js editor would be at:

/home/m3/repos/three.js/editor

Now, I change the Lorca counter example source code like this, note that http.Dir()
is setting an absolute path:

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		log.Fatal(err)
	}
	defer ln.Close()
	go http.Serve(ln, http.FileServer(http.Dir("/home/m3/repos/three.js/editor")))
	ui.Load(fmt.Sprintf("http://%s", ln.Addr()))

The commit diff would be:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

But I get these 404 (Not Found) errors:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

Second approach

I keep a copy of Lorca counter example here:

/home/m3/go/src/lorca-3d-editor

Then, I copy the whole three.js source code over here:

/home/m3/go/src/lorca-3d-editor/three.js

So, the web app source code would be at:

/home/m3/go/src/lorca-3d-editor/three.js/editor

Now, I change the Lorca counter example source code like this, note that http.Dir("three.js/editor") is setting a relative path:

	ln, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		log.Fatal(err)
	}
	defer ln.Close()
	go http.Serve(ln, http.FileServer(http.Dir("three.js/editor")))
	ui.Load(fmt.Sprintf("http://%s", ln.Addr()))

Now I'm getting some 404 (Not Found) again:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

Possible problem

Possibly, the problem is that the web app inside three.js/editor is referencing some files throughout the three.js repository. But when serving a Go HTTP server of static files inside three.js/editor, the HTTP server cannot find all the external files which are scattered throughout three.js repository referenced by contents of three.js/editor or contents of three.js repository itself. What would be the best practice to resolve such problem?

答案1

得分: 1

这里是Lorca反例的副本:

/home/m3/go/src/lorca-3d-editor

同时,整个three.js源代码位于:

/home/m3/go/src/lorca-3d-editor/three.js

因此,Web应用程序的源代码将位于:

/home/m3/go/src/lorca-3d-editor/three.js/editor

现在,通过以下提交解决了该问题:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

现在,Lorca可以正常运行ThreeJS编辑器:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

英文:

Keeping a copy of Lorca counter example here:

/home/m3/go/src/lorca-3d-editor

Also, keeping the whole three.js source code at:

/home/m3/go/src/lorca-3d-editor/three.js

So, the web app source code would be at:

/home/m3/go/src/lorca-3d-editor/three.js/editor

Now, the problem is resolved by such a commit:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

Now ThreeJS editor runs fine by Lorca:

将Web应用程序转换为Lorca桌面应用程序时出现404(未找到)错误。

huangapple
  • 本文由 发表于 2021年7月18日 17:27:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/68427754.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定