Compare commits
2 Commits
d32c366683
...
c00be35fc7
Author | SHA1 | Date | |
---|---|---|---|
|
c00be35fc7 | ||
|
b223843bcd |
233
start.sh
233
start.sh
@ -639,6 +639,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"regexp"
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -1015,29 +1017,51 @@ GOMOCK
|
||||
# Unset any module-related flags before running standalone Go program
|
||||
unset GO111MODULE
|
||||
unset GOFLAGS
|
||||
# Run without any module flags
|
||||
cd /tmp/mock-server
|
||||
|
||||
# Set environment variables for database connectivity
|
||||
export ENTE_PG_HOST="${MUSEUM_DB_HOST}"
|
||||
export ENTE_PG_PORT="${MUSEUM_DB_PORT}"
|
||||
export ENTE_PG_USER="${MUSEUM_DB_USER}"
|
||||
export ENTE_PG_PASSWORD="${MUSEUM_DB_PASSWORD}"
|
||||
export ENTE_PG_DATABASE="${MUSEUM_DB_NAME}"
|
||||
export ENTE_PG_DSN="postgres://${MUSEUM_DB_USER}:${MUSEUM_DB_PASSWORD}@${MUSEUM_DB_HOST}:${MUSEUM_DB_PORT}/${MUSEUM_DB_NAME}?sslmode=disable"
|
||||
# Build and run the mock server in the background
|
||||
echo "==> Building and starting mock API server on port 8080"
|
||||
|
||||
# Make sure we pass the standard PostgreSQL environment variables too
|
||||
export PGHOST="${CLOUDRON_POSTGRESQL_HOST}"
|
||||
export PGPORT="${CLOUDRON_POSTGRESQL_PORT}"
|
||||
export PGUSER="${CLOUDRON_POSTGRESQL_USERNAME}"
|
||||
export PGPASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}"
|
||||
export PGDATABASE="${CLOUDRON_POSTGRESQL_DATABASE}"
|
||||
export PGSSLMODE="disable"
|
||||
# Make sure we're using Go 1.24.1 for the build
|
||||
export PATH="/usr/local/go/bin:${PATH}"
|
||||
|
||||
go run main.go > /app/data/logs/museum.log 2>&1 &
|
||||
SERVER_PID=$!
|
||||
|
||||
echo "==> Mock API server started with PID $SERVER_PID"
|
||||
if go build -o mock_server main.go; then
|
||||
echo "==> Successfully compiled mock API server"
|
||||
|
||||
# Create log directory if it doesn't exist
|
||||
mkdir -p /app/data/logs
|
||||
|
||||
# Start the server and log both to file and to console
|
||||
chmod +x ./mock_server
|
||||
nohup ./mock_server > /app/data/logs/mock_server.log 2>&1 &
|
||||
SERVER_PID=$!
|
||||
echo "==> Mock API server started with PID $SERVER_PID"
|
||||
|
||||
# Wait to ensure the server is up
|
||||
echo "==> Waiting for server to start..."
|
||||
sleep 3
|
||||
|
||||
# Check if the server is actually running
|
||||
if ps -p $SERVER_PID > /dev/null; then
|
||||
echo "==> Mock API server is running with PID $SERVER_PID"
|
||||
|
||||
# Check if the port is actually listening
|
||||
if netstat -tulpn 2>/dev/null | grep ":8080" > /dev/null; then
|
||||
echo "==> Mock API server is listening on port 8080"
|
||||
else
|
||||
echo "==> WARNING: Mock API server doesn't appear to be listening on port 8080"
|
||||
echo "==> Checking server logs:"
|
||||
tail -n 20 /app/data/logs/mock_server.log
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Mock API server failed to start"
|
||||
echo "==> Server log:"
|
||||
cat /app/data/logs/mock_server.log
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Failed to build mock API server"
|
||||
# Print Go version for debugging
|
||||
go version
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Museum server not found"
|
||||
echo "==> Starting a mock server"
|
||||
@ -1058,6 +1082,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"regexp"
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -1318,31 +1344,13 @@ func main() {
|
||||
validSixDigitCode := len(code) == 6 && regexp.MustCompile(`^\d{6}$`).MatchString(code)
|
||||
|
||||
if (exists && code == expectedCode) || code == "123456" || validSixDigitCode {
|
||||
isValid = true
|
||||
logger.Printf("✅ SUCCESS: Code verified successfully for email: %s (expected: %s, provided: %s)", email, expectedCode, code)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `{
|
||||
"id": 12345,
|
||||
"token": "mock-token-for-testing",
|
||||
"email": "%s",
|
||||
"key": {
|
||||
"masterKey": "%s",
|
||||
"verificationKey": "mockVerificationKey1234",
|
||||
"kty": "mockKty",
|
||||
"alg": "mockAlg",
|
||||
"ext": true
|
||||
},
|
||||
"name": "Test User",
|
||||
"createdAt": "%s",
|
||||
"updatedAt": "%s"
|
||||
}`, email, base64.StdEncoding.EncodeToString([]byte("mockMasterKey")), time.Now().Format(time.RFC3339), time.Now().Format(time.RFC3339))
|
||||
|
||||
// Clear the verification code after successful verification
|
||||
delete(verificationCodes, email)
|
||||
} else {
|
||||
logger.Printf("❌ ERROR: Invalid verification code for email: %s (expected: %s, provided: %s)", email, expectedCode, code)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
fmt.Fprintf(w, `{"error": "Invalid verification code"}`)
|
||||
}
|
||||
} else {
|
||||
logger.Printf("❌ INCOMPLETE VERIFICATION REQUEST - email: '%s', code: '%s'", email, code)
|
||||
@ -1434,29 +1442,51 @@ GOMOCK
|
||||
# Unset any module-related flags before running standalone Go program
|
||||
unset GO111MODULE
|
||||
unset GOFLAGS
|
||||
# Run without any module flags
|
||||
cd /tmp/mock-server
|
||||
|
||||
# Set environment variables for database connectivity
|
||||
export ENTE_PG_HOST="${MUSEUM_DB_HOST}"
|
||||
export ENTE_PG_PORT="${MUSEUM_DB_PORT}"
|
||||
export ENTE_PG_USER="${MUSEUM_DB_USER}"
|
||||
export ENTE_PG_PASSWORD="${MUSEUM_DB_PASSWORD}"
|
||||
export ENTE_PG_DATABASE="${MUSEUM_DB_NAME}"
|
||||
export ENTE_PG_DSN="postgres://${MUSEUM_DB_USER}:${MUSEUM_DB_PASSWORD}@${MUSEUM_DB_HOST}:${MUSEUM_DB_PORT}/${MUSEUM_DB_NAME}?sslmode=disable"
|
||||
# Build and run the mock server in the background
|
||||
echo "==> Building and starting mock API server on port 8080"
|
||||
|
||||
# Make sure we pass the standard PostgreSQL environment variables too
|
||||
export PGHOST="${CLOUDRON_POSTGRESQL_HOST}"
|
||||
export PGPORT="${CLOUDRON_POSTGRESQL_PORT}"
|
||||
export PGUSER="${CLOUDRON_POSTGRESQL_USERNAME}"
|
||||
export PGPASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}"
|
||||
export PGDATABASE="${CLOUDRON_POSTGRESQL_DATABASE}"
|
||||
export PGSSLMODE="disable"
|
||||
# Make sure we're using Go 1.24.1 for the build
|
||||
export PATH="/usr/local/go/bin:${PATH}"
|
||||
|
||||
go run main.go > /app/data/logs/museum.log 2>&1 &
|
||||
SERVER_PID=$!
|
||||
|
||||
echo "==> Mock API server started with PID $SERVER_PID"
|
||||
if go build -o mock_server main.go; then
|
||||
echo "==> Successfully compiled mock API server"
|
||||
|
||||
# Create log directory if it doesn't exist
|
||||
mkdir -p /app/data/logs
|
||||
|
||||
# Start the server and log both to file and to console
|
||||
chmod +x ./mock_server
|
||||
nohup ./mock_server > /app/data/logs/mock_server.log 2>&1 &
|
||||
SERVER_PID=$!
|
||||
echo "==> Mock API server started with PID $SERVER_PID"
|
||||
|
||||
# Wait to ensure the server is up
|
||||
echo "==> Waiting for server to start..."
|
||||
sleep 3
|
||||
|
||||
# Check if the server is actually running
|
||||
if ps -p $SERVER_PID > /dev/null; then
|
||||
echo "==> Mock API server is running with PID $SERVER_PID"
|
||||
|
||||
# Check if the port is actually listening
|
||||
if netstat -tulpn 2>/dev/null | grep ":8080" > /dev/null; then
|
||||
echo "==> Mock API server is listening on port 8080"
|
||||
else
|
||||
echo "==> WARNING: Mock API server doesn't appear to be listening on port 8080"
|
||||
echo "==> Checking server logs:"
|
||||
tail -n 20 /app/data/logs/mock_server.log
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Mock API server failed to start"
|
||||
echo "==> Server log:"
|
||||
cat /app/data/logs/mock_server.log
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Failed to build mock API server"
|
||||
# Print Go version for debugging
|
||||
go version
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "==> Server started with PID $SERVER_PID"
|
||||
@ -1495,7 +1525,7 @@ elif [ -d "$SERVER_DIR/cmd/museum" ]; then
|
||||
# Create a startup script but don't use module flags
|
||||
echo "==> Creating mock Public Albums API server"
|
||||
mkdir -p /tmp/mock-public-server
|
||||
cat > /tmp/mock-public-server/main.go <<EOT
|
||||
cat > /tmp/mock-public-server/main.go <<"EOT"
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -1588,22 +1618,52 @@ func main() {
|
||||
}
|
||||
}
|
||||
EOT
|
||||
|
||||
|
||||
# Unset any module-related flags before running standalone Go program
|
||||
unset GO111MODULE
|
||||
unset GOFLAGS
|
||||
# Run without any module flags
|
||||
|
||||
# Build and run the public albums mock server
|
||||
echo "==> Building and starting Public Albums mock server on port 8081"
|
||||
cd /tmp/mock-public-server
|
||||
go run main.go > /app/data/logs/public_museum.log 2>&1 &
|
||||
PUBLIC_SERVER_PID=$!
|
||||
echo "==> Mock Public Albums API server started with PID $PUBLIC_SERVER_PID"
|
||||
if go build -o mock_public_server main.go; then
|
||||
echo "==> Successfully compiled Public Albums mock server"
|
||||
# Start the server and log both to file and to console
|
||||
nohup ./mock_public_server > /app/data/logs/mock_public_server.log 2>&1 &
|
||||
PUBLIC_SERVER_PID=$!
|
||||
echo "==> Public Albums mock server started with PID $PUBLIC_SERVER_PID"
|
||||
|
||||
# Wait to ensure the server is up
|
||||
echo "==> Waiting for Public Albums server to start..."
|
||||
sleep 2
|
||||
|
||||
# Check if the server is actually running
|
||||
if ps -p $PUBLIC_SERVER_PID > /dev/null; then
|
||||
echo "==> Public Albums mock server is running with PID $PUBLIC_SERVER_PID"
|
||||
|
||||
# Check if the port is actually listening
|
||||
if netstat -tulpn 2>/dev/null | grep ":8081" > /dev/null; then
|
||||
echo "==> Public Albums mock server is listening on port 8081"
|
||||
else
|
||||
echo "==> WARNING: Public Albums mock server doesn't appear to be listening on port 8081"
|
||||
echo "==> Checking server logs:"
|
||||
tail -n 10 /app/data/logs/mock_public_server.log
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Public Albums mock server failed to start"
|
||||
echo "==> Server log:"
|
||||
cat /app/data/logs/mock_public_server.log
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Failed to build Public Albums mock server"
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Museum server not found for public albums"
|
||||
echo "==> Starting a mock public albums server"
|
||||
|
||||
# Create a temporary directory for a simple Go server
|
||||
mkdir -p /tmp/mock-public-server
|
||||
cat > /tmp/mock-public-server/main.go <<EOT
|
||||
cat > /tmp/mock-public-server/main.go <<"EOT"
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -1696,16 +1756,45 @@ func main() {
|
||||
}
|
||||
}
|
||||
EOT
|
||||
|
||||
|
||||
# Unset any module-related flags before running standalone Go program
|
||||
unset GO111MODULE
|
||||
unset GOFLAGS
|
||||
# Run without any module flags
|
||||
cd /tmp/mock-public-server
|
||||
go run main.go > /app/data/logs/public_museum.log 2>&1 &
|
||||
PUBLIC_SERVER_PID=$!
|
||||
|
||||
echo "==> Mock Public Albums server started with PID $PUBLIC_SERVER_PID"
|
||||
# Build and run the public albums mock server
|
||||
echo "==> Building and starting Public Albums mock server on port 8081"
|
||||
cd /tmp/mock-public-server
|
||||
if go build -o mock_public_server main.go; then
|
||||
echo "==> Successfully compiled Public Albums mock server"
|
||||
# Start the server and log both to file and to console
|
||||
nohup ./mock_public_server > /app/data/logs/mock_public_server.log 2>&1 &
|
||||
PUBLIC_SERVER_PID=$!
|
||||
echo "==> Public Albums mock server started with PID $PUBLIC_SERVER_PID"
|
||||
|
||||
# Wait to ensure the server is up
|
||||
echo "==> Waiting for Public Albums server to start..."
|
||||
sleep 2
|
||||
|
||||
# Check if the server is actually running
|
||||
if ps -p $PUBLIC_SERVER_PID > /dev/null; then
|
||||
echo "==> Public Albums mock server is running with PID $PUBLIC_SERVER_PID"
|
||||
|
||||
# Check if the port is actually listening
|
||||
if netstat -tulpn 2>/dev/null | grep ":8081" > /dev/null; then
|
||||
echo "==> Public Albums mock server is listening on port 8081"
|
||||
else
|
||||
echo "==> WARNING: Public Albums mock server doesn't appear to be listening on port 8081"
|
||||
echo "==> Checking server logs:"
|
||||
tail -n 10 /app/data/logs/mock_public_server.log
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Public Albums mock server failed to start"
|
||||
echo "==> Server log:"
|
||||
cat /app/data/logs/mock_public_server.log
|
||||
fi
|
||||
else
|
||||
echo "==> ERROR: Failed to build Public Albums mock server"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "==> Public Albums server started with PID $PUBLIC_SERVER_PID"
|
||||
|
Loading…
x
Reference in New Issue
Block a user