mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-08-28 19:40:28 +00:00
Rejig embedded assets to a central folder
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"io"
|
||||
"io/fs"
|
||||
@@ -10,19 +9,19 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"npm/embed"
|
||||
h "npm/internal/api/http"
|
||||
)
|
||||
|
||||
//go:embed assets
|
||||
var assets embed.FS
|
||||
var assetsSub fs.FS
|
||||
|
||||
var errIsDir = errors.New("path is dir")
|
||||
var (
|
||||
assetsSub fs.FS
|
||||
errIsDir = errors.New("path is dir")
|
||||
)
|
||||
|
||||
// NotFound is a json error handler for 404's and method not allowed.
|
||||
// It also serves the react frontend as embedded files in the golang binary.
|
||||
func NotFound() func(http.ResponseWriter, *http.Request) {
|
||||
assetsSub, _ = fs.Sub(assets, "assets")
|
||||
assetsSub, _ = fs.Sub(embed.Assets, "assets")
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
path := strings.TrimLeft(r.URL.Path, "/")
|
||||
|
@@ -3,10 +3,11 @@ package handler
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"npm/doc"
|
||||
"npm/embed"
|
||||
"npm/internal/api/schema"
|
||||
"npm/internal/config"
|
||||
"npm/internal/logger"
|
||||
@@ -15,7 +16,10 @@ import (
|
||||
"github.com/jc21/jsref/provider"
|
||||
)
|
||||
|
||||
var swaggerSchema []byte
|
||||
var (
|
||||
swaggerSchema []byte
|
||||
apiDocsSub fs.FS
|
||||
)
|
||||
|
||||
// Schema simply reads the swagger schema from disk and returns is raw
|
||||
// Route: GET /schema
|
||||
@@ -29,8 +33,10 @@ func Schema() func(http.ResponseWriter, *http.Request) {
|
||||
|
||||
func getSchema() []byte {
|
||||
if swaggerSchema == nil {
|
||||
apiDocsSub, _ = fs.Sub(embed.APIDocFiles, "api_docs")
|
||||
|
||||
// nolint:gosec
|
||||
swaggerSchema, _ = doc.SwaggerFiles.ReadFile("api.swagger.json")
|
||||
swaggerSchema, _ = fs.ReadFile(apiDocsSub, "api.swagger.json")
|
||||
|
||||
// Replace {{VERSION}} with Config Version
|
||||
swaggerSchema = []byte(strings.ReplaceAll(string(swaggerSchema), "{{VERSION}}", config.Version))
|
||||
@@ -42,7 +48,7 @@ func getSchema() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
provider := provider.NewIoFS(doc.SwaggerFiles, "")
|
||||
provider := provider.NewIoFS(apiDocsSub, "")
|
||||
resolver := jsref.New()
|
||||
err := resolver.AddProvider(provider)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user