我正在尝试使用embedd来包含SvelteKit网站的单个二进制文件。我使用Chi作为我的路由器。但是我无法让它工作。我得到了以下其中一种选项。据我所知,embedd的
有人能给我一些指导吗? 示例存储库
文件结构:
all:
选项确保包括以_
为前缀的文件。我还尝试了在主V1中的StripPrefix
方法中的不同变体:/uibuild/
或uibuild/
等等...有人能给我一些指导吗? 示例存储库
- 目录列表(在我的情况下是`uibuild`)
- 在chrome控制台上,根路径"/"显示空白页面,但是嵌套文件返回404
- 主页"/"返回404。
Svelte 配置: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))
文件结构:
.
├── 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
/about
),那么您需要为这些请求路径返回索引(或者,如我链接的答案中所述,任何没有匹配文件的路径)。 - Brits/about
),那么您需要为这些请求路径返回索引(或者,如我链接的答案中所述,任何没有匹配文件的路径)。 - Brits