tsk-10: CORS support (#28)
Closes #10 Reviewed-on: phoenix/textsender-auth#28 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -19,6 +19,7 @@ type Config struct {
|
||||
ServerPort string
|
||||
ResetDB bool
|
||||
EnableRegistration bool
|
||||
AllowedOrigins []string
|
||||
}
|
||||
|
||||
type ConnectionInfo struct {
|
||||
@@ -67,12 +68,23 @@ func Load() *Config {
|
||||
|
||||
unpackedConnString := UnpackDBConnString()
|
||||
dbConnString := unpackedConnString.Parse()
|
||||
allowedOrigins := unpackAllowedOrigin()
|
||||
|
||||
return &Config{
|
||||
DBConnString: dbConnString,
|
||||
ServerPort: *port,
|
||||
ResetDB: *resetDb,
|
||||
EnableRegistration: CheckRegistration(),
|
||||
if len(allowedOrigins) > 0 {
|
||||
return &Config{
|
||||
DBConnString: dbConnString,
|
||||
ServerPort: *port,
|
||||
ResetDB: *resetDb,
|
||||
EnableRegistration: CheckRegistration(),
|
||||
AllowedOrigins: allowedOrigins,
|
||||
}
|
||||
} else {
|
||||
return &Config{
|
||||
DBConnString: dbConnString,
|
||||
ServerPort: *port,
|
||||
ResetDB: *resetDb,
|
||||
EnableRegistration: CheckRegistration(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +143,12 @@ func UnpackDBConnString() (connInfo ConnectionInfo) {
|
||||
return
|
||||
}
|
||||
|
||||
func unpackAllowedOrigin() []string {
|
||||
allowedOriginsRaw := os.Getenv("ALLOWED_ORIGINS")
|
||||
allowedOriginsSplit := strings.Split(allowedOriginsRaw, ",")
|
||||
return allowedOriginsSplit
|
||||
}
|
||||
|
||||
func CheckRegistration() bool {
|
||||
if flagValue := os.Getenv("ENABLE_REGISTRATION"); flagValue != "" {
|
||||
if val := strings.ToUpper(flagValue); val == "TRUE" {
|
||||
|
||||
Reference in New Issue
Block a user