Я использовал функции 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
работает нормально после того, как я добавил gorilla/mux, но файлы css и javascript не загружаются.
Я получаю ту же проблему при использовании реакции js и ajax-solr
Изменил эту строку:
http.Handle("/", http.FileServer(http.Dir("views")))
В это:
r.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("views"))))
Почему это работает?
Пожалуйста, приведите краткий самодостаточный пример. Например, вы не указываете реализацию
ngxMappingHandler
.