使用golang服务器可以运行颤振web构建吗?Golang有为html文件提供服务的便利,而颤振web以index.html和js文件的形式提供输出。如果有可能的话,那么戈朗代码应该是什么样的呢?
发布于 2019-12-14 11:49:35
正如友好的文档所提到的,我相信你必须构建你的应用程序。
https://flutter.dev/docs/get-started/web#build
运行以下命令以生成发布版本:
flutter build web这会将构建的文件(包括资产目录)填充到build/web目录中,这些文件需要一起使用。
,golang代码应该是什么样的?
就像其他普通的HTTP服务器一样。
http.Handle("/build/web/", http.StripPrefix("/build/web/", http.FileServer(http.Dir("build/web"))))
http.ListenAndServe(":8080", nil)发布于 2020-04-02 06:49:52
package main
import (
"flag"
"log"
"net/http"
)
func main() {
port := flag.String("p", "8181", "port to serve on")
directory := flag.String("d", "web", "the directory of static file to host")
flag.Parse()
http.Handle("/", http.FileServer(http.Dir(*directory)))
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
log.Fatal(http.ListenAndServe(":"+*port, nil))
}只需复制网页文件夹到你的围棋应用程序。
https://stackoverflow.com/questions/59334011
复制相似问题