我正在try 使用嵌入的单一二进制文件来包含SvelteKit网站.我使用Chi作为我的路由.但我不能让它起作用.我得到了下面这些选项中的一个.据我所知,Embeddall:
选项确保包含以_
为前缀的文件.我还在Main V1:/uibuild/
或uibuild/
等版本中try 了StripPrefix
方法的变体.
有没有人能给它点光?
- 目录列表(S),在我的例子中是`uiBuild`
- 空白页在"/"但在Chrome控制台404‘S上的嵌套文件
- 404在主页"/"上.
Svelte config:个
import preprocess from "svelte-preprocess";
import adapter from "@sveltejs/adapter-static";
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
pages: "./../server/uibuild",
assets: "./../server/uibuild",
fallback: "index.html",
}),
},
preprocess: [
preprocess({
postcss: true,
}),
],
};
export default config;
Main.go V1:个
这会给出错误3.
package main
import (
"embed"
"log"
"net/http"
chi "github.com/go-chi/chi/v5"
)
//go:embed all:uibuild
var svelteStatic embed.FS
func main() {
r := chi.NewRouter()
r.Handle("/", http.StripPrefix("/uibuild", http.FileServer(http.FS(svelteStatic))))
log.Fatal(http.ListenAndServe(":8082", r))
}
Main.go V2:个
这将显示错误2.
static, err := fs.Sub(svelteStatic, "uibuild")
if err != nil {
panic(err)
}
r := chi.NewRouter()
r.Handle("/", http.FileServer(http.FS(static)))
log.Fatal(http.ListenAndServe(":8082", r))
File structure:个
.
├── go.mod
├── go.sum
├── main.go
└── uibuild
├── _app
│ ├── immutable
│ │ ├── assets
│ │ │ ├── 0.d7cb9c3b.css
│ │ │ └── _layout.d7cb9c3b.css
│ │ ├── chunks
│ │ │ ├── index.6dba6488.js
│ │ │ └── singletons.b716dd01.js
│ │ ├── entry
│ │ │ ├── app.c5e2a2d5.js
│ │ │ └── start.58733315.js
│ │ └── nodes
│ │ ├── 0.ba05e72f.js
│ │ ├── 1.f4999e32.js
│ │ └── 2.ad52e74a.js
│ └── version.json
├── favicon.png
└── index.html