This commit is contained in:
程广 2025-04-14 17:35:12 +08:00
parent f57bd4d937
commit 5fdb7de83d
4 changed files with 234 additions and 113 deletions

3
.vscode/launch.json vendored
View File

@ -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"]
}
]
}

View File

@ -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

View File

@ -13,7 +13,10 @@
},
"categories": {
"default": {
"appenders": [ "out" ,"stdout"],
"appenders": [
"out",
"stdout"
],
"level": "debug"
}
}
@ -31,103 +34,206 @@
"paths": [
{
"path": "/",
"upstreams": ["http://localhost:4200"],
"directives":["HostSchemas $target"]
}
],
"jwt":{
"secret": "cloudops",
"expiresIn": "1h",
"issuer": "cloudops",
"audience": "cloudops"
"root": "./adminui",
"default": "index.html"
}
]
},
"servers":[{
"servers": [
{
"port": 3001,
"name": "installui",
"directives": [
"Gzip_Response"
],
"paths":[
{
"path": "/",
"upstreams": [
"http://localhost:4200"
],
"directives": [
"HostSchemas $target"
]
},
{
"path":"/ib",
"upstreams": [
"http://localhost:8080"
],
"directives": [
"HostSchemas $target"
]
}
]
},
{
"port": 3000,
"name": "cloudops",
"directives": [
"Gzip_Response"
],
"paths": [
{
"path": "/",
"upstreams": [
"http://localhost:4200"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/ssologin",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://localhost:4200"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/themes",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"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": "/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"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/platform/version",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/v1/patrolrecords",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/v1/standingbook",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/v1/resource",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/v1/config",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/v1/workflow",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/token/check",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/v1/messages",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/cloudops-state/",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"upstreams": [
"http://192.168.12.157:9880"
],
"directives": [
"HostSchemas $target"
]
},
{
"path": "/socket.io/",
"upstreams": ["http://192.168.12.157:9880"],
"directives":["HostSchemas $target"]
"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.157:9880"],
"upstreams": [
"http://192.168.12.204:1662"
],
"directives": [
"HostSchemas $target",
"HeaderOrigin",
"RemoveCookie token"
]
},
{
"path":"/ib",
"upstreams": [
"http://localhost:8080"
],
"directives": [
"HostSchemas $target",
"HeaderOrigin",
@ -135,5 +241,6 @@
]
}
]
}]
}
]
}

View File

@ -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")
}