【发布时间】:2019-09-13 21:20:38
【问题描述】:
我使用的是 golang net/http 函数并且没有错误,但我需要自定义 URL,所以我实现了 gorilla/mux 路由器,现在出现如下错误:
The resource from “http://localhost:8080/styles.css” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).
The resource from “http://localhost:8080/main.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).
The resource from “http://localhost:8080/base.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).
之前的代码:
http.Handle("/transcode", http.HandlerFunc(transcodeHandler))
http.Handle("/tctype", http.HandlerFunc(tctypeHandler))
http.Handle("/sse/dashboard", lp.B)
http.Handle("/upload", http.HandlerFunc(uploadHandler))
http.Handle("/", http.FileServer(http.Dir("views")))
fmt.Println("Listening on port: 8080...")
log.Fatalf("Exited: %s", http.ListenAndServe(":8080", nil))
之后的代码:
r := mux.NewRouter()
r.Handle("/ngx/mapping/{name}", http.HandlerFunc(ngxMappingHandler))
r.Handle("/transcode", http.HandlerFunc(transcodeHandler))
r.Handle("/tctype", http.HandlerFunc(tctypeHandler))
r.Handle("/sse/dashboard", lp.B)
r.Handle("/upload", http.HandlerFunc(uploadHandler))
r.Handle("/", http.FileServer(http.Dir("views")))
fmt.Println("Listening on port: 8080...")
log.Fatalf("Exited: %s", http.ListenAndServe(":8080", r))
【问题讨论】:
-
请提供一个简短的、独立的示例。比如你不指定
ngxMappingHandler的实现。 -
我认为没有必要,因为
ngxMappingHandler在我添加 gorilla/mux 后工作正常,但 css 和 javascript 文件无法加载。 -
我在使用 react js 和 ajax-solr 时遇到了同样的问题
标签: go mime-types gorilla mux