Fix here-document syntax issues in runtime config generation and Go module setup for mock API server
This commit is contained in:
parent
5dbbb094b4
commit
defe47f78d
85
start.sh
85
start.sh
@ -1066,16 +1066,18 @@ else
|
|||||||
echo "==> ERROR: Museum server not found"
|
echo "==> ERROR: Museum server not found"
|
||||||
echo "==> Starting a mock server"
|
echo "==> Starting a mock server"
|
||||||
|
|
||||||
# Create a temporary directory for a simple Go server
|
# Create a temporary directory for a simple Go server with correct permissions
|
||||||
mkdir -p /tmp/mock-server
|
mkdir -p /tmp/mock-server
|
||||||
cd /tmp/mock-server
|
cd /tmp/mock-server
|
||||||
|
|
||||||
# Initialize a proper Go module
|
# Create a simple Go module setup
|
||||||
echo "==> Initializing Go module for mock API server"
|
echo "==> Creating proper Go module structure"
|
||||||
go mod init mock-server
|
touch go.mod
|
||||||
|
echo "module mock-server" > go.mod
|
||||||
|
|
||||||
# Write the program to a file with proper quoting
|
# Write main.go correctly
|
||||||
cat > main.go << 'GOMOCK'
|
echo "==> Writing main.go for mock API server"
|
||||||
|
cat > main.go << EOF
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -1454,7 +1456,7 @@ func main() {
|
|||||||
logger.Fatalf("Server failed: %v", err)
|
logger.Fatalf("Server failed: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GOMOCK
|
EOF
|
||||||
|
|
||||||
# Completely unset Go module-related environment variables
|
# Completely unset Go module-related environment variables
|
||||||
echo "==> Unsetting module flags before building mock server"
|
echo "==> Unsetting module flags before building mock server"
|
||||||
@ -1463,24 +1465,23 @@ GOMOCK
|
|||||||
unset GOMODCACHE
|
unset GOMODCACHE
|
||||||
unset GOPATH
|
unset GOPATH
|
||||||
|
|
||||||
# Build and run the mock server in the background
|
# Show directory content for debugging
|
||||||
echo "==> Building and starting mock API server on port 8080"
|
echo "==> Current directory contents:"
|
||||||
ls -la
|
ls -la
|
||||||
|
|
||||||
# Show go.mod for debugging
|
# Build and run the mock server in the background
|
||||||
echo "==> Go module file contents:"
|
echo "==> Building and starting mock API server on port 8080"
|
||||||
cat go.mod
|
|
||||||
|
|
||||||
# Build the mock server (explicitly in current directory)
|
# Build without specifying the file (shorter command)
|
||||||
if go build -o mock_server .; then
|
if go build -v .; then
|
||||||
echo "==> Successfully compiled mock API server"
|
echo "==> Successfully compiled mock API server"
|
||||||
|
|
||||||
# Create log directory if it doesn't exist
|
# Create log directory if it doesn't exist
|
||||||
mkdir -p /app/data/logs
|
mkdir -p /app/data/logs
|
||||||
|
|
||||||
# Start the server and log both to file and to console
|
# Start the server and log both to file and to console
|
||||||
chmod +x ./mock_server
|
chmod +x ./mock-server
|
||||||
nohup ./mock_server > /app/data/logs/mock_server.log 2>&1 &
|
nohup ./mock-server > /app/data/logs/mock_server.log 2>&1 &
|
||||||
SERVER_PID=$!
|
SERVER_PID=$!
|
||||||
echo "==> Mock API server started with PID $SERVER_PID"
|
echo "==> Mock API server started with PID $SERVER_PID"
|
||||||
|
|
||||||
@ -1877,34 +1878,34 @@ EOT
|
|||||||
# Create runtime-config.js files in writable locations
|
# Create runtime-config.js files in writable locations
|
||||||
echo "==> Creating runtime-config.js in writable location"
|
echo "==> Creating runtime-config.js in writable location"
|
||||||
mkdir -p /app/data/web
|
mkdir -p /app/data/web
|
||||||
cat > /app/data/web/runtime-config.js << 'EOT'
|
cat << EOF > /app/data/web/runtime-config.js
|
||||||
// Runtime configuration for Ente
|
// Runtime configuration for Ente
|
||||||
window.ENTE_CONFIG = {
|
window.ENTE_CONFIG = {
|
||||||
API_URL: '${API_ENDPOINT}',
|
API_URL: '${API_ENDPOINT}',
|
||||||
PUBLIC_ALBUMS_URL: '${CLOUDRON_APP_ORIGIN}/public'
|
PUBLIC_ALBUMS_URL: '${CLOUDRON_APP_ORIGIN}/public'
|
||||||
};
|
};
|
||||||
|
|
||||||
// Next.js environment variables
|
// Next.js environment variables
|
||||||
window.process = window.process || {};
|
window.process = window.process || {};
|
||||||
window.process.env = window.process.env || {};
|
window.process.env = window.process.env || {};
|
||||||
window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT = '${API_ENDPOINT}';
|
window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT = '${API_ENDPOINT}';
|
||||||
window.process.env.NEXT_PUBLIC_ENTE_PUBLIC_ALBUMS_ENDPOINT = '${CLOUDRON_APP_ORIGIN}/public';
|
window.process.env.NEXT_PUBLIC_ENTE_PUBLIC_ALBUMS_ENDPOINT = '${CLOUDRON_APP_ORIGIN}/public';
|
||||||
window.process.env.NEXT_PUBLIC_REACT_APP_ENTE_ENDPOINT = '${API_ENDPOINT}';
|
window.process.env.NEXT_PUBLIC_REACT_APP_ENTE_ENDPOINT = '${API_ENDPOINT}';
|
||||||
window.process.env.REACT_APP_ENTE_ENDPOINT = '${API_ENDPOINT}';
|
window.process.env.REACT_APP_ENTE_ENDPOINT = '${API_ENDPOINT}';
|
||||||
|
|
||||||
// Make sure all URLs are properly formatted for URL constructor
|
// Make sure all URLs are properly formatted for URL constructor
|
||||||
if (!window.ENTE_CONFIG.API_URL.startsWith('http')) {
|
if (!window.ENTE_CONFIG.API_URL.startsWith('http')) {
|
||||||
console.log('Adding https:// prefix to API_URL');
|
console.log('Adding https:// prefix to API_URL');
|
||||||
window.ENTE_CONFIG.API_URL = window.location.origin + window.ENTE_CONFIG.API_URL;
|
window.ENTE_CONFIG.API_URL = window.location.origin + window.ENTE_CONFIG.API_URL;
|
||||||
window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT = window.location.origin + window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT = window.location.origin + window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
|
||||||
window.process.env.REACT_APP_ENTE_ENDPOINT = window.location.origin + window.process.env.REACT_APP_ENTE_ENDPOINT;
|
window.process.env.REACT_APP_ENTE_ENDPOINT = window.location.origin + window.process.env.REACT_APP_ENTE_ENDPOINT;
|
||||||
window.process.env.NEXT_PUBLIC_REACT_APP_ENTE_ENDPOINT = window.location.origin + window.process.env.NEXT_PUBLIC_REACT_APP_ENTE_ENDPOINT;
|
window.process.env.NEXT_PUBLIC_REACT_APP_ENTE_ENDPOINT = window.location.origin + window.process.env.NEXT_PUBLIC_REACT_APP_ENTE_ENDPOINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Ente runtime config loaded from runtime-config.js');
|
console.log('Ente runtime config loaded from runtime-config.js');
|
||||||
console.log('API_URL:', window.ENTE_CONFIG.API_URL);
|
console.log('API_URL:', window.ENTE_CONFIG.API_URL);
|
||||||
console.log('PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
|
console.log('PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
|
||||||
EOT
|
EOF
|
||||||
|
|
||||||
# Update the variables in the runtime config
|
# Update the variables in the runtime config
|
||||||
sed -i "s|\${API_ENDPOINT}|${API_ENDPOINT}|g" /app/data/web/runtime-config.js
|
sed -i "s|\${API_ENDPOINT}|${API_ENDPOINT}|g" /app/data/web/runtime-config.js
|
||||||
@ -1954,17 +1955,17 @@ HTML
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Modify the Caddyfile to serve our modified HTML files
|
# Modify the Caddyfile to serve our modified HTML files
|
||||||
cat > /app/data/caddy/Caddyfile <<EOT
|
cat << EOF > /app/data/caddy/Caddyfile
|
||||||
# Global settings
|
# Global settings
|
||||||
{
|
{
|
||||||
admin off
|
admin off
|
||||||
auto_https off
|
auto_https off
|
||||||
http_port $CADDY_PORT
|
http_port $CADDY_PORT
|
||||||
https_port 0
|
https_port 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main site configuration
|
# Main site configuration
|
||||||
:$CADDY_PORT {
|
:$CADDY_PORT {
|
||||||
# Basic logging
|
# Basic logging
|
||||||
log {
|
log {
|
||||||
level INFO
|
level INFO
|
||||||
@ -2160,8 +2161,8 @@ HTML
|
|||||||
uri strip_prefix /public
|
uri strip_prefix /public
|
||||||
reverse_proxy 0.0.0.0:$PUBLIC_ALBUMS_PORT
|
reverse_proxy 0.0.0.0:$PUBLIC_ALBUMS_PORT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOT
|
EOF
|
||||||
|
|
||||||
echo "==> Created Caddy config with properly modified HTML files at /app/data/caddy/Caddyfile"
|
echo "==> Created Caddy config with properly modified HTML files at /app/data/caddy/Caddyfile"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user