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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user