Add content-type header for generated config.js

This commit is contained in:
Tomaž Jerman
2022-07-14 13:52:14 +02:00
parent 72ae80aaf9
commit f41b7872f4
+5
View File
@@ -123,6 +123,11 @@ func serveIndex(opt options.HttpServerOpt, indexHTML []byte, serve http.Handler)
func serveConfig(r chi.Router, config webappConfig) {
r.Get(options.CleanBase(config.appUrl, "config.js"), func(w http.ResponseWriter, r *http.Request) {
// Assure the content-type
// The presence of the X-Content-Type-Options: nosniff header breaks web applications
w.Header().Add("Content-Type", "text/javascript")
const line = "window.%s = '%s';\n"
_, _ = fmt.Fprintf(w, line, "CortezaAPI", config.apiBaseUrl)
_, _ = fmt.Fprintf(w, line, "CortezaAuth", config.authBaseUrl)