大猩猩使用变量设置静态文件的错误路径

问题描述 投票:0回答:1

我设置了以下路由:

func (app *application) routes() *mux.Router {
    r := mux.NewRouter()
    fs := http.FileServer(http.Dir("./ui/static/"))
    r.PathPrefix("/ui/static/").Handler(http.StripPrefix("/ui/static/", fs))

    authRequired := r.PathPrefix("/").Subrouter()

    authRequired.HandleFunc("/foo", app.foo).Methods("POST") // <- this one works fine
    authRequired.HandleFunc("/bar/{id:[0-9]+}", app.bar) // <- this does not

    return r
}

当我调用URL http://server/foo时,一切都很好。与例如http://server/bar/1网站已交付,但我收到类似[]的错误消息

The resource "http://server/bar/ui/static/css/style.css" has been blocked due to mime type mismatch

/bar中的http://server/bar/ui/static/...不应该存在。我该如何解决?

我设置了以下路由:func(应用程序*应用程序)route()* mux.Router {r:= mux.NewRouter()fs:= http.FileServer(http.Dir(“ ./ ui / static / “))r.PathPrefix(” / ui / static /“)....

go gorilla mux
1个回答
2
投票
The resource "http://server/bar/ui/static/css/style.css" has been blocked due to mime type mismatch
© www.soinside.com 2019 - 2024. All rights reserved.