diff --git a/.vscode/launch.json b/.vscode/launch.json index cf6b164..35e027f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Launch", "type": "go", "request": "launch", - "mode": "auto", + "mode": "debug", "program": "${workspaceFolder}", "env": { "GODEBUG": "cgocheck=0", @@ -20,6 +20,7 @@ ], "showLog": true, "trace": "log", + "dlvFlags": ["--check-go-version=false"] } ] } \ No newline at end of file diff --git a/Makefile b/Makefile index d5aa699..ca343e5 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,15 @@ -BINARY_NAME=target/gohttpd +ARCHS := amd64 arm64 +VERSION ?= $(shell git describe --tags --always) +all:$(ARCHS) -all:build - -build: - go build -o ${BINARY_NAME} - cp config.json target/ - cp -r adminui target/ - cp gohttpd.service target/ - cp install.sh target/ +$(ARCHS): + @echo "Building for $(@)" + @GOOS=linux GOARCH=$(@) + go build -ldflags "-X main.Version=$(VERSION)" -o target/$(@)/gohttpd + cp config.json target/$(@)/ + cp -r adminui target/$(@)/ + cp gohttpd.service target/$(@)/ + cp install.sh target/$(@)/ clean: go clean diff --git a/config.json b/config.json index 59e3441..513961b 100644 --- a/config.json +++ b/config.json @@ -1,29 +1,32 @@ { - "logging" :{ + "logging": { "appenders": { - "out" :{ + "out": { "type": "file", - "options":{ + "options": { "file": "gohttpd.log" } }, - "stdout":{ + "stdout": { "type": "console" } }, "categories": { "default": { - "appenders": [ "out" ,"stdout"], + "appenders": [ + "out", + "stdout" + ], "level": "debug" } } }, - "admin" : { + "admin": { "name": "admin", - "port" : 8088, + "port": 8088, "username": "admin", "password": "admin", - "directives":[ + "directives": [ "Set-Header Access-Control-Allow-Origin *", "Set-Header Access-Control-Allow-Methods GET, POST, PUT, DELETE, OPTIONS", "Set-Header Access-Control-Allow-Headers Content-Type, Authorization, Content-Length, X-Requested-With" @@ -31,109 +34,213 @@ "paths": [ { "path": "/", - "upstreams": ["http://localhost:4200"], - "directives":["HostSchemas $target"] + "root": "./adminui", + "default": "index.html" } - ], - "jwt":{ - "secret": "cloudops", - "expiresIn": "1h", - "issuer": "cloudops", - "audience": "cloudops" - } + ] }, - "servers":[{ - "port": 3000, - "name": "cloudops", - "directives":[ + "servers": [ + { + "port": 3001, + "name": "installui", + "directives": [ "Gzip_Response" ], "paths":[ - { - "path" : "/ssologin", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] + "path": "/", + "upstreams": [ + "http://localhost:4200" + ], + "directives": [ + "HostSchemas $target" + ] }, { - "path" : "/themes", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/security/login", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/security/logout", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/v1/relational/assets", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/platform/version", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/v1/patrolrecords", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/v1/standingbook", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/v1/resource", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/v1/config", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/v1/workflow", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path":"/token/check", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/v1/messages", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/cloudops-state/", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path":"/socket.io/", - "upstreams": ["http://192.168.12.157:9880"], - "directives":["HostSchemas $target"] - }, - { - "path" : "/thing", - "upstreams": ["http://192.168.12.157:9880"], - "directives":[ - "HostSchemas $target", - "HeaderOrigin", - "RemoveCookie token" + "path":"/ib", + "upstreams": [ + "http://localhost:8080" + ], + "directives": [ + "HostSchemas $target" ] } ] - }] -} \ No newline at end of file + }, + { + "port": 3000, + "name": "cloudops", + "directives": [ + "Gzip_Response" + ], + "paths": [ + { + "path": "/", + "upstreams": [ + "http://localhost:4200" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/ssologin", + "upstreams": [ + "http://localhost:4200" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/themes", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/security", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/v1/relational/assets", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/platform/version", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/v1/patrolrecords", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/v1/standingbook", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/v1/resource", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/v1/config", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/v1/workflow", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/token/check", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/v1/messages", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/cloudops-state/", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/socket.io/", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/v1/stream", + "upstreams": [ + "http://192.168.12.157:9880" + ], + "directives": [ + "HostSchemas $target" + ] + }, + { + "path": "/thing", + "upstreams": [ + "http://192.168.12.204:1662" + ], + "directives": [ + "HostSchemas $target", + "HeaderOrigin", + "RemoveCookie token" + ] + }, + { + "path":"/ib", + "upstreams": [ + "http://localhost:8080" + ], + "directives": [ + "HostSchemas $target", + "HeaderOrigin", + "RemoveCookie token" + ] + } + ] + } + ] +} diff --git a/handler/file.go b/handler/file.go index a07cd48..2df563a 100644 --- a/handler/file.go +++ b/handler/file.go @@ -3,6 +3,7 @@ package handler import ( "errors" "io/fs" + "mime" "net/http" "os" "path/filepath" @@ -66,3 +67,13 @@ func FileExists(name string) (os.FileInfo, bool, error) { func NewFileHandler(f FileHandler) http.Handler { return http.FileServer(f) } + +func init() { + mime.AddExtensionType(".js", "application/javascript") + mime.AddExtensionType(".css", "text/css") + mime.AddExtensionType(".html", "text/html") + mime.AddExtensionType(".htm", "text/html") + mime.AddExtensionType(".svg", "image/svg+xml") + mime.AddExtensionType(".png", "image/png") + mime.AddExtensionType(".mjs", "application/javascript") +}