nade CORS allowed origins a variable
This commit is contained in:
parent
ccb53c85c6
commit
0f33941e65
16
main.go
16
main.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
@ -18,10 +19,21 @@ var (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
configFile := os.Getenv("CONFIG")
|
configFile := os.Getenv("BOXES_API_CONFIG")
|
||||||
var err error
|
var err error
|
||||||
config, err = LoadConfig(configFile)
|
config, err = LoadConfig(configFile)
|
||||||
|
|
||||||
|
// Get the allowed origins from the ALLOWED_ORIGINS environment variable
|
||||||
|
// If empty, defaults to http://localhost:3000
|
||||||
|
allowedOrigins := os.Getenv("BOXES_API_ALLOWED_ORIGINS")
|
||||||
|
origins := []string{"http://localhost:3000"} // Default value
|
||||||
|
|
||||||
|
if allowedOrigins != "" {
|
||||||
|
// Split the comma-separated string into a slice of strings
|
||||||
|
origins = strings.Split(allowedOrigins, ",")
|
||||||
|
fmt.Println("Listening for connections from: ", origins)
|
||||||
|
}
|
||||||
|
|
||||||
// check for errors
|
// check for errors
|
||||||
if err != nil || config == nil {
|
if err != nil || config == nil {
|
||||||
log.Fatalf("Failed to load config: %v", err)
|
log.Fatalf("Failed to load config: %v", err)
|
||||||
|
@ -77,7 +89,7 @@ func main() {
|
||||||
|
|
||||||
// Apply CORS middleware
|
// Apply CORS middleware
|
||||||
c := cors.New(cors.Options{
|
c := cors.New(cors.Options{
|
||||||
AllowedOrigins: []string{"http://localhost:3000", "http://10.0.0.16:3000"}, // Change this to your frontend domain
|
AllowedOrigins: origins,
|
||||||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||||
AllowedHeaders: []string{"Authorization", "Content-Type"},
|
AllowedHeaders: []string{"Authorization", "Content-Type"},
|
||||||
ExposedHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Cache-Control", "Content-Language", "Content-Type", "Expires", "Last-Modified", "Pragma", "ETag"},
|
ExposedHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Cache-Control", "Content-Language", "Content-Type", "Expires", "Last-Modified", "Pragma", "ETag"},
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/binb/ash
|
||||||
|
|
||||||
|
# Set the password you want to use
|
||||||
|
PASSWORD="12m0nk3ys"
|
||||||
|
|
||||||
|
# Use htpasswd to create a bcrypt hash of the password
|
||||||
|
HASHED_PASSWORD=$(htpasswd -nbBC 10 "" "$PASSWORD" | tr -d ':\n')
|
||||||
|
|
||||||
|
# Create the user in the SQLite database
|
||||||
|
sqlite3 your_database.db "INSERT INTO users (username, password, email, email, email, email, email, email, email, email, email) VALUES ('boxuser', '$HASHED_PASSWORD','boxuser@r8z.us');"
|
Loading…
Reference in New Issue