2026-04-06 15:48:37 +05:30
|
|
|
// Copyright IBM Corp. 2020, 2026
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2020-07-07 19:57:54 -04:00
|
|
|
package controller
|
2020-06-30 11:26:22 -04:00
|
|
|
|
|
|
|
|
import (
|
2021-07-28 06:31:16 -04:00
|
|
|
"context"
|
2020-06-30 11:26:22 -04:00
|
|
|
"net/http"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
2026-10-12 10:33:41 -07:00
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/event"
|
2020-06-30 11:26:22 -04:00
|
|
|
)
|
|
|
|
|
|
2021-10-14 12:13:07 -04:00
|
|
|
func devUiPassthroughHandler(uiPassthroughDir string) http.Handler {
|
2021-07-28 06:31:16 -04:00
|
|
|
const op = "controller.devPassthroughHandler"
|
|
|
|
|
ctx := context.TODO()
|
2020-06-30 11:26:22 -04:00
|
|
|
// Panic may not be ideal but this is never a production call and it'll
|
|
|
|
|
// panic on startup. We could also just change the function to return
|
|
|
|
|
// an error.
|
2021-10-14 12:13:07 -04:00
|
|
|
abs, err := filepath.Abs(uiPassthroughDir)
|
2020-06-30 11:26:22 -04:00
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2021-07-28 06:31:16 -04:00
|
|
|
event.WriteSysEvent(ctx, op, "serving passthrough files at /", "path", abs)
|
2020-06-30 11:26:22 -04:00
|
|
|
fs := http.FileServer(http.Dir(abs))
|
|
|
|
|
prefixHandler := http.StripPrefix("/", fs)
|
|
|
|
|
|
|
|
|
|
return prefixHandler
|
|
|
|
|
}
|
2020-07-07 19:57:54 -04:00
|
|
|
|
|
|
|
|
var handleUi = func(c *Controller) http.Handler {
|
2021-10-14 12:13:07 -04:00
|
|
|
if c.conf.RawConfig.DevUiPassthroughDir != "" {
|
|
|
|
|
return devUiPassthroughHandler(c.conf.RawConfig.DevUiPassthroughDir)
|
2020-07-07 19:57:54 -04:00
|
|
|
}
|
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
})
|
|
|
|
|
}
|