gpt4 book ai didi

go - MIME 类型 (“text/plain” ) 不匹配 (X-Content-Type-Options : nosniff)

转载 作者:数据小太阳 更新时间:2023-10-29 03:19:45 30 4
gpt4 key购买 nike

我使用的是 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))

最佳答案

更改了这一行:

http.Handle("/", http.FileServer(http.Dir("views")))

进入这个:

r.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("views"))))

关于go - MIME 类型 (“text/plain” ) 不匹配 (X-Content-Type-Options : nosniff),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55832398/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com