tsk-4: Adding CORS support (#53)

Closes #4

Reviewed-on: phoenix/textsender-api#53
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-12-21 00:28:17 +00:00
committed by phoenix
parent 69b5f4ff89
commit f5f753fe02
5 changed files with 14 additions and 1 deletions
+10
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"strconv"
"strings"
"git.kundeng.us/phoenix/textsender-models/tx0/config"
"github.com/joho/godotenv"
@@ -18,6 +19,7 @@ type Config struct {
ResetDB bool
JWTSecret string `env:"JWT_SECRET" required:"true"`
TwilioConfig *config.TwiloConfig
AllowedOrigins []string
}
type ConnectionInfo struct {
@@ -68,11 +70,13 @@ func Load() (*Config, *config.TwiloConfig, error) {
if cfg, err := TwilioConfig(); err != nil {
return nil, nil, err
} else {
allowedOrigins := unpackAllowedOrigins()
return &Config{
DBConnString: dbConnString,
ServerPort: *port,
ResetDB: *resetDb,
JWTSecret: os.Getenv("JWT_SECRET"),
AllowedOrigins: allowedOrigins,
}, cfg, nil
}
}
@@ -128,6 +132,12 @@ func UnpackDBConnString() (connInfo ConnectionInfo) {
return
}
func unpackAllowedOrigins() []string {
allowedOriginsRaw := os.Getenv("ALLOWED_ORIGINS")
allowedOriginsSplit := strings.Split(allowedOriginsRaw, ",")
return allowedOriginsSplit
}
func TwilioConfig() (*config.TwiloConfig, error) {
authSid := os.Getenv("TWILIO_AUTH_SID")
serviceSid := os.Getenv("TWILIO_SERVICE_SID")