add new enviroment variables and remove cli flags
This commit is contained in:
7
backend/env/env.go
vendored
7
backend/env/env.go
vendored
@@ -17,12 +17,15 @@ const (
|
|||||||
PrivKey EnvKey = "PRIVKEY"
|
PrivKey EnvKey = "PRIVKEY"
|
||||||
Fullchain EnvKey = "FULLCHAIN"
|
Fullchain EnvKey = "FULLCHAIN"
|
||||||
Https EnvKey = "HTTPS"
|
Https EnvKey = "HTTPS"
|
||||||
Url EnvKey = "URL"
|
HostUrl EnvKey = "HOST_URL"
|
||||||
Port EnvKey = "PORT"
|
HostPort EnvKey = "HOST_PORT"
|
||||||
WorkingDir EnvKey = "WORKING_DIR"
|
WorkingDir EnvKey = "WORKING_DIR"
|
||||||
Spa EnvKey = "SPA"
|
Spa EnvKey = "SPA"
|
||||||
AccessSecret EnvKey = "ACCESS_SECRET"
|
AccessSecret EnvKey = "ACCESS_SECRET"
|
||||||
RefreshSecret EnvKey = "REFRESH_SECRET"
|
RefreshSecret EnvKey = "REFRESH_SECRET"
|
||||||
|
Organization EnvKey = "ORGANIZATION"
|
||||||
|
DOMAIN EnvKey = "DOMAIN"
|
||||||
|
AllowOrigin EnvKey = "ALLOWORIGIN"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ GIN_MODE=release
|
|||||||
DEBUG=false
|
DEBUG=false
|
||||||
SPA=directory_of_spa_files
|
SPA=directory_of_spa_files
|
||||||
WORKING_DIR=.
|
WORKING_DIR=.
|
||||||
URL=your_local_url
|
HOST_URL=your_local_url
|
||||||
PORT=your_local_port
|
HOST_PORT=your_local_port
|
||||||
HTTPS=true
|
HTTPS=true
|
||||||
PRIVKEY=your_certificate_key_file
|
PRIVKEY=your_certificate_key_file
|
||||||
FULLCHAIN=your_certificate_fullchain_file
|
FULLCHAIN=your_certificate_fullchain_file
|
||||||
ACCESS_SECRET=your_32bit_long_access_secret
|
ACCESS_SECRET=your_32bit_long_access_secret
|
||||||
REFRESH_SECRET=your_32bit_long_referesh_secret
|
REFRESH_SECRET=your_32bit_long_referesh_secret
|
||||||
|
ALLOWORIGIN=all_allowed_urls
|
||||||
|
DOMAIN=your_domain
|
||||||
@@ -3,7 +3,7 @@ module backend
|
|||||||
go 1.24.5
|
go 1.24.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.tecamino.com/paadi/access-handler v1.0.22
|
gitea.tecamino.com/paadi/access-handler v1.0.23
|
||||||
gitea.tecamino.com/paadi/memberDB v1.1.2
|
gitea.tecamino.com/paadi/memberDB v1.1.2
|
||||||
gitea.tecamino.com/paadi/tecamino-dbm v0.1.1
|
gitea.tecamino.com/paadi/tecamino-dbm v0.1.1
|
||||||
gitea.tecamino.com/paadi/tecamino-logger v0.2.1
|
gitea.tecamino.com/paadi/tecamino-logger v0.2.1
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
gitea.tecamino.com/paadi/access-handler v1.0.22 h1:XFi2PQ1gWqe9YuSye4Ti1o5TpdV0AFpt4Fb58MFMagk=
|
gitea.tecamino.com/paadi/access-handler v1.0.23 h1:bsQgGEyiV8nutZbkNKCDkHWhIpOUEMV22wePxQsn3QU=
|
||||||
gitea.tecamino.com/paadi/access-handler v1.0.22/go.mod h1:wKsB5/Rvaj580gdg3+GbUf5V/0N00XN6cID+C/8135M=
|
gitea.tecamino.com/paadi/access-handler v1.0.23/go.mod h1:wKsB5/Rvaj580gdg3+GbUf5V/0N00XN6cID+C/8135M=
|
||||||
gitea.tecamino.com/paadi/dbHandler v1.0.8 h1:ZWSBM/KFtLwTv2cBqwK1mOxWAxAfL0BcWEC3kJ9JALU=
|
gitea.tecamino.com/paadi/dbHandler v1.0.8 h1:ZWSBM/KFtLwTv2cBqwK1mOxWAxAfL0BcWEC3kJ9JALU=
|
||||||
gitea.tecamino.com/paadi/dbHandler v1.0.8/go.mod h1:y/xn/POJg1DO++67uKvnO23lJQgh+XFQq7HZCS9Getw=
|
gitea.tecamino.com/paadi/dbHandler v1.0.8/go.mod h1:y/xn/POJg1DO++67uKvnO23lJQgh+XFQq7HZCS9Getw=
|
||||||
gitea.tecamino.com/paadi/memberDB v1.1.2 h1:j/Tsr7JnzAkdOvgjG77TzTVBWd4vBrmEFzPXNpW7GYk=
|
gitea.tecamino.com/paadi/memberDB v1.1.2 h1:j/Tsr7JnzAkdOvgjG77TzTVBWd4vBrmEFzPXNpW7GYk=
|
||||||
|
|||||||
@@ -24,12 +24,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var allowOrigins models.StringSlice
|
// set cli flage
|
||||||
|
|
||||||
flag.Var(&allowOrigins, "allowOrigin", "Allowed origin (can repeat this flag)")
|
|
||||||
|
|
||||||
envFile := flag.String("env", ".env", "enviroment file")
|
envFile := flag.String("env", ".env", "enviroment file")
|
||||||
organization := flag.String("organization", "", "self signed ciertificate organization")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// load enviroment file if exists
|
// load enviroment file if exists
|
||||||
@@ -51,6 +47,16 @@ func main() {
|
|||||||
os.Chdir(workingDir)
|
os.Chdir(workingDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//set allowed origins
|
||||||
|
var allowOrigins models.StringSlice
|
||||||
|
|
||||||
|
if strings.Contains(env.DOMAIN.GetValue(), "http") {
|
||||||
|
allowOrigins.Set(env.DOMAIN.GetValue())
|
||||||
|
}
|
||||||
|
if env.AllowOrigin.GetValue() != "" {
|
||||||
|
allowOrigins.Set(env.AllowOrigin.GetValue())
|
||||||
|
}
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not get working directory: %v", err)
|
log.Fatalf("Could not get working directory: %v", err)
|
||||||
@@ -103,6 +109,8 @@ func main() {
|
|||||||
allowOrigins = append(allowOrigins, fmt.Sprintf("%s%s:9000", httpString, localIP), fmt.Sprintf("%s%s:9500", httpString, localIP))
|
allowOrigins = append(allowOrigins, fmt.Sprintf("%s%s:9000", httpString, localIP), fmt.Sprintf("%s%s:9500", httpString, localIP))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println(100, allowOrigins)
|
||||||
|
|
||||||
s.Routes.Use(cors.New(cors.Config{
|
s.Routes.Use(cors.New(cors.Config{
|
||||||
AllowOrigins: allowOrigins,
|
AllowOrigins: allowOrigins,
|
||||||
//AllowOrigins: []string{"*"},
|
//AllowOrigins: []string{"*"},
|
||||||
@@ -181,7 +189,7 @@ func main() {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
if err := utils.OpenBrowser(fmt.Sprintf("%slocalhost:%s", httpString, env.Port.GetValue()), logger); err != nil {
|
if err := utils.OpenBrowser(fmt.Sprintf("%slocalhost:%s", httpString, env.HostPort.GetValue()), logger); err != nil {
|
||||||
logger.Error("main", fmt.Sprintf("starting browser error : %s", err))
|
logger.Error("main", fmt.Sprintf("starting browser error : %s", err))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -197,16 +205,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start https server
|
// start https server
|
||||||
logger.Info("main", fmt.Sprintf("https listen on ip: %s port: %s", env.Url.GetValue(), env.Port.GetValue()))
|
logger.Info("main", fmt.Sprintf("https listen on ip: %s port: %s", env.HostUrl.GetValue(), env.HostPort.GetValue()))
|
||||||
if err := s.ServeHttps(env.Url.GetValue(), env.Port.GetUIntValue(), cert.Cert{Organization: *organization, CertFile: env.Fullchain.GetValue(), KeyFile: env.PrivKey.GetValue()}); err != nil {
|
if err := s.ServeHttps(env.HostUrl.GetValue(), env.HostPort.GetUIntValue(), cert.Cert{Organization: env.Organization.GetValue(), CertFile: env.Fullchain.GetValue(), KeyFile: env.PrivKey.GetValue()}); err != nil {
|
||||||
logger.Error("main", "error https server "+err.Error())
|
logger.Error("main", "error https server "+err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// start http server
|
// start http server
|
||||||
logger.Info("main", fmt.Sprintf("http listen on ip: %s port: %s", env.Url.GetValue(), env.Port.GetValue()))
|
logger.Info("main", fmt.Sprintf("http listen on ip: %s port: %s", env.HostUrl.GetValue(), env.HostPort.GetValue()))
|
||||||
if err := s.ServeHttp(env.Url.GetValue(), env.Port.GetUIntValue()); err != nil {
|
if err := s.ServeHttp(env.HostUrl.GetValue(), env.HostPort.GetUIntValue()); err != nil {
|
||||||
logger.Error("main", "error http server "+err.Error())
|
logger.Error("main", "error http server "+err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import "strings"
|
|||||||
|
|
||||||
type StringSlice []string
|
type StringSlice []string
|
||||||
|
|
||||||
func (s *StringSlice) String() string {
|
func (s *StringSlice) Set(value string) {
|
||||||
return strings.Join(*s, ",")
|
if strings.Contains(value, ",") {
|
||||||
|
*s = append(*s, strings.Split(value, ",")...)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StringSlice) Set(value string) error {
|
|
||||||
*s = append(*s, value)
|
*s = append(*s, value)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user