Move the server daemons into their own package (#2061)
* Move the server daemons into their own package With this change the internal/server package now is dedicated to the server domain (workers and controllers) and not to the server daemons. The hope is that this will make it easier to keep the daemons decoupled from the representation of the servers in the database.
This commit is contained in:
177 files changed
+275
-275
No files matched your search
@@ -0,0 +1,60 @@
|
||||
//go:build ui
|
||||
// +build ui
|
||||
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/ui"
|
||||
)
|
||||
|
||||
func init() {
|
||||
handleUi = handleUiWithAssets
|
||||
}
|
||||
|
||||
func handleUiWithAssets(c *Controller) http.Handler {
|
||||
var nextHandler http.Handler
|
||||
if c.conf.RawConfig.DevUiPassthroughDir != "" {
|
||||
nextHandler = devUiPassthroughHandler(c.conf.RawConfig.DevUiPassthroughDir)
|
||||
} else {
|
||||
nextHandler = ui.Handler()
|
||||
}
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
dotIndex := strings.LastIndex(r.URL.Path, ".")
|
||||
switch dotIndex {
|
||||
case -1:
|
||||
// For all paths without an extension serve /index.html
|
||||
r.URL.Path = "/"
|
||||
|
||||
default:
|
||||
switch r.URL.Path {
|
||||
case "/", "/favicon.png", "/assets/styles.css":
|
||||
|
||||
default:
|
||||
for i := dotIndex + 1; i < len(r.URL.Path); i++ {
|
||||
intVal := r.URL.Path[i]
|
||||
// Current guidance from FE is if it's only alphanum after
|
||||
// the last dot, treat it as an extension
|
||||
if intVal < '0' ||
|
||||
(intVal > '9' && intVal < 'A') ||
|
||||
(intVal > 'Z' && intVal < 'a') ||
|
||||
intVal > 'z' {
|
||||
// Not an extension. Serve the contents of index.html
|
||||
r.URL.Path = "/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall through to the next handler
|
||||
nextHandler.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user