[英]Serving static files recursively with go
I'm using sveltekit as my frontend for an app I'm working on.我正在使用 sveltekit 作为我正在开发的应用程序的前端。 I've chosen a static adapter in the svelte.config.js which outputs all necessary components as static files.
我在 svelte.config.js 中选择了一个 static 适配器,它将所有必要的组件输出为 static 文件。 Here is the structure of my static directory.
这是我的 static 目录的结构。
The upper most files load, however, files in static/_app do not最上面的文件加载,然而,静态/_app 中的文件不加载
func main() {
router := mux.NewRouter()
router.Handle("/", http.FileServer(http.Dir("static")))
router.HandleFunc("/large-files", largeFilesHandler).Methods("OPTIONS", "POST")
router.HandleFunc("/delete-file", deleteFileHandler).Methods("DELETE", "OPTIONS")
logrus.SetLevel(logrus.ErrorLevel)
err := http.ListenAndServe(":8000", router)
if err != nil {
logrus.Fatal(err)
}
}
And in my svelte.config.js在我的 svelte.config.js
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
adapter: adapter({
pages: '../static',
assets: '../static',
})
,
prerender: { default: true }
}
};
export default config;
Update:更新:
If I remove the html files, I get the directory list, but all of these options fail with a 404如果我删除 html 文件,我会得到目录列表,但所有这些选项都会失败并显示 404
mux handles static files differently. mux 以不同方式处理 static 文件。
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static")))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.