Fixed Caddy filter directive and Go import issues
This commit is contained in:
parent
43cb685842
commit
bdcf96150f
234
start.sh
234
start.sh
@ -637,24 +637,33 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
port := "8080"
|
port := "8080"
|
||||||
|
|
||||||
log.Println("Starting mock Ente API server on port", port)
|
fmt.Println("Starting mock Ente API server on port", port)
|
||||||
log.Println("This is a standalone mock server that doesn't require any Ente modules")
|
log.Println("This is a standalone mock server that doesn't require any Ente modules")
|
||||||
|
|
||||||
// Log some environment variables for debugging
|
// Log some environment variables for debugging
|
||||||
log.Println("Environment variables:")
|
fmt.Println("Environment variables:")
|
||||||
log.Println("PGHOST:", os.Getenv("PGHOST"))
|
fmt.Println("PGHOST:", os.Getenv("PGHOST"))
|
||||||
log.Println("PGPORT:", os.Getenv("PGPORT"))
|
fmt.Println("PGPORT:", os.Getenv("PGPORT"))
|
||||||
log.Println("API_ENDPOINT:", os.Getenv("ENTE_API_ENDPOINT"))
|
fmt.Println("API_ENDPOINT:", os.Getenv("ENTE_API_ENDPOINT"))
|
||||||
|
|
||||||
// Create a logger that logs to both stdout and a file
|
// Create a logger that logs to both stdout and a file
|
||||||
os.MkdirAll("/app/data/logs", 0755) // Ensure the logs directory exists
|
os.MkdirAll("/app/data/logs", 0755) // Ensure the logs directory exists
|
||||||
logFile, err := os.OpenFile("/app/data/logs/api_requests.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
logFile, err := os.OpenFile("/app/data/logs/api_requests.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error opening log file: %v", err)
|
fmt.Printf("Error opening log file: %v\n", err)
|
||||||
}
|
}
|
||||||
defer logFile.Close()
|
defer func() {
|
||||||
|
if logFile != nil {
|
||||||
|
logFile.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
multiWriter := io.MultiWriter(os.Stdout, logFile)
|
var multiWriter io.Writer
|
||||||
|
if logFile != nil {
|
||||||
|
multiWriter = io.MultiWriter(os.Stdout, logFile)
|
||||||
|
} else {
|
||||||
|
multiWriter = os.Stdout
|
||||||
|
}
|
||||||
logger := log.New(multiWriter, "", log.LstdFlags)
|
logger := log.New(multiWriter, "", log.LstdFlags)
|
||||||
|
|
||||||
// Initialize random seed
|
// Initialize random seed
|
||||||
@ -701,6 +710,7 @@ func main() {
|
|||||||
|
|
||||||
// Return a success response
|
// Return a success response
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
// Use the encoding/json package to create and send the response
|
// Use the encoding/json package to create and send the response
|
||||||
jsonResponse := map[string]string{
|
jsonResponse := map[string]string{
|
||||||
@ -815,7 +825,9 @@ func main() {
|
|||||||
logger.Printf("Mock Ente API server listening on port %s\n", port)
|
logger.Printf("Mock Ente API server listening on port %s\n", port)
|
||||||
|
|
||||||
// Make sure we listen on all interfaces, not just localhost
|
// Make sure we listen on all interfaces, not just localhost
|
||||||
|
fmt.Printf("Starting HTTP server on 0.0.0.0:%s\n", port)
|
||||||
if err := http.ListenAndServe("0.0.0.0:" + port, nil); err != nil {
|
if err := http.ListenAndServe("0.0.0.0:" + port, nil); err != nil {
|
||||||
|
fmt.Printf("Server failed: %v\n", err)
|
||||||
logger.Fatalf("Server failed: %v", err)
|
logger.Fatalf("Server failed: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -958,24 +970,33 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
port := "8081"
|
port := "8081"
|
||||||
|
|
||||||
log.Println("Starting mock Public Albums API server on port", port)
|
fmt.Println("Starting mock Public Albums API server on port", port)
|
||||||
log.Println("This is a standalone mock server that doesn't require any Ente modules")
|
log.Println("This is a standalone mock server that doesn't require any Ente modules")
|
||||||
|
|
||||||
// Log some environment variables for debugging
|
// Log some environment variables for debugging
|
||||||
log.Println("Environment variables:")
|
fmt.Println("Environment variables:")
|
||||||
log.Println("PGHOST:", os.Getenv("PGHOST"))
|
fmt.Println("PGHOST:", os.Getenv("PGHOST"))
|
||||||
log.Println("PGPORT:", os.Getenv("PGPORT"))
|
fmt.Println("PGPORT:", os.Getenv("PGPORT"))
|
||||||
log.Println("API_ENDPOINT:", os.Getenv("ENTE_API_ENDPOINT"))
|
fmt.Println("API_ENDPOINT:", os.Getenv("ENTE_API_ENDPOINT"))
|
||||||
|
|
||||||
// Create a logger that logs to both stdout and a file
|
// Create a logger that logs to both stdout and a file
|
||||||
os.MkdirAll("/app/data/logs", 0755) // Ensure the logs directory exists
|
os.MkdirAll("/app/data/logs", 0755) // Ensure the logs directory exists
|
||||||
logFile, err := os.OpenFile("/app/data/logs/public_api_requests.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
logFile, err := os.OpenFile("/app/data/logs/public_api_requests.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error opening log file: %v", err)
|
fmt.Printf("Error opening log file: %v\n", err)
|
||||||
}
|
}
|
||||||
defer logFile.Close()
|
defer func() {
|
||||||
|
if logFile != nil {
|
||||||
|
logFile.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
multiWriter := io.MultiWriter(os.Stdout, logFile)
|
var multiWriter io.Writer
|
||||||
|
if logFile != nil {
|
||||||
|
multiWriter = io.MultiWriter(os.Stdout, logFile)
|
||||||
|
} else {
|
||||||
|
multiWriter = os.Stdout
|
||||||
|
}
|
||||||
logger := log.New(multiWriter, "", log.LstdFlags)
|
logger := log.New(multiWriter, "", log.LstdFlags)
|
||||||
|
|
||||||
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -1004,6 +1025,9 @@ func main() {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
// Use fmt.Fprintf to explicitly use the fmt package
|
||||||
|
fmt.Fprintf(w, "{\"status\":\"processing\"}")
|
||||||
|
|
||||||
// Use json package to create the response
|
// Use json package to create the response
|
||||||
response := map[string]string{
|
response := map[string]string{
|
||||||
"status": "mock",
|
"status": "mock",
|
||||||
@ -1018,7 +1042,9 @@ func main() {
|
|||||||
logger.Printf("Mock Public Albums API server listening on port %s\n", port)
|
logger.Printf("Mock Public Albums API server listening on port %s\n", port)
|
||||||
|
|
||||||
// Make sure we listen on all interfaces
|
// Make sure we listen on all interfaces
|
||||||
|
fmt.Printf("Starting Public Albums HTTP server on 0.0.0.0:%s\n", port)
|
||||||
if err := http.ListenAndServe("0.0.0.0:" + port, nil); err != nil {
|
if err := http.ListenAndServe("0.0.0.0:" + port, nil); err != nil {
|
||||||
|
fmt.Printf("Public Albums server failed: %v\n", err)
|
||||||
logger.Fatalf("Server failed: %v", err)
|
logger.Fatalf("Server failed: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1054,24 +1080,33 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
port := "8081"
|
port := "8081"
|
||||||
|
|
||||||
log.Println("Starting mock Public Albums API server on port", port)
|
fmt.Println("Starting mock Public Albums API server on port", port)
|
||||||
log.Println("This is a standalone mock server that doesn't require any Ente modules")
|
log.Println("This is a standalone mock server that doesn't require any Ente modules")
|
||||||
|
|
||||||
// Log some environment variables for debugging
|
// Log some environment variables for debugging
|
||||||
log.Println("Environment variables:")
|
fmt.Println("Environment variables:")
|
||||||
log.Println("PGHOST:", os.Getenv("PGHOST"))
|
fmt.Println("PGHOST:", os.Getenv("PGHOST"))
|
||||||
log.Println("PGPORT:", os.Getenv("PGPORT"))
|
fmt.Println("PGPORT:", os.Getenv("PGPORT"))
|
||||||
log.Println("API_ENDPOINT:", os.Getenv("ENTE_API_ENDPOINT"))
|
fmt.Println("API_ENDPOINT:", os.Getenv("ENTE_API_ENDPOINT"))
|
||||||
|
|
||||||
// Create a logger that logs to both stdout and a file
|
// Create a logger that logs to both stdout and a file
|
||||||
os.MkdirAll("/app/data/logs", 0755) // Ensure the logs directory exists
|
os.MkdirAll("/app/data/logs", 0755) // Ensure the logs directory exists
|
||||||
logFile, err := os.OpenFile("/app/data/logs/public_api_requests.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
logFile, err := os.OpenFile("/app/data/logs/public_api_requests.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error opening log file: %v", err)
|
fmt.Printf("Error opening log file: %v\n", err)
|
||||||
}
|
}
|
||||||
defer logFile.Close()
|
defer func() {
|
||||||
|
if logFile != nil {
|
||||||
|
logFile.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
multiWriter := io.MultiWriter(os.Stdout, logFile)
|
var multiWriter io.Writer
|
||||||
|
if logFile != nil {
|
||||||
|
multiWriter = io.MultiWriter(os.Stdout, logFile)
|
||||||
|
} else {
|
||||||
|
multiWriter = os.Stdout
|
||||||
|
}
|
||||||
logger := log.New(multiWriter, "", log.LstdFlags)
|
logger := log.New(multiWriter, "", log.LstdFlags)
|
||||||
|
|
||||||
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -1100,6 +1135,9 @@ func main() {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
// Use fmt.Fprintf to explicitly use the fmt package
|
||||||
|
fmt.Fprintf(w, "{\"status\":\"processing\"}")
|
||||||
|
|
||||||
// Use json package to create the response
|
// Use json package to create the response
|
||||||
response := map[string]string{
|
response := map[string]string{
|
||||||
"status": "mock",
|
"status": "mock",
|
||||||
@ -1114,7 +1152,9 @@ func main() {
|
|||||||
logger.Printf("Mock Public Albums API server listening on port %s\n", port)
|
logger.Printf("Mock Public Albums API server listening on port %s\n", port)
|
||||||
|
|
||||||
// Make sure we listen on all interfaces
|
// Make sure we listen on all interfaces
|
||||||
|
fmt.Printf("Starting Public Albums HTTP server on 0.0.0.0:%s\n", port)
|
||||||
if err := http.ListenAndServe("0.0.0.0:" + port, nil); err != nil {
|
if err := http.ListenAndServe("0.0.0.0:" + port, nil); err != nil {
|
||||||
|
fmt.Printf("Public Albums server failed: %v\n", err)
|
||||||
logger.Fatalf("Server failed: %v", err)
|
logger.Fatalf("Server failed: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1224,11 +1264,6 @@ cat > /app/data/caddy/Caddyfile <<EOT
|
|||||||
|
|
||||||
console.log('Ente config loaded - API_URL:', window.ENTE_CONFIG.API_URL);
|
console.log('Ente config loaded - API_URL:', window.ENTE_CONFIG.API_URL);
|
||||||
console.log('Ente config loaded - PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
|
console.log('Ente config loaded - PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
|
||||||
|
|
||||||
// Dynamically inject the config by creating script elements
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
console.log('DOM loaded, injecting runtime config as needed');
|
|
||||||
});
|
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1237,21 +1272,50 @@ cat > /app/data/caddy/Caddyfile <<EOT
|
|||||||
file_server
|
file_server
|
||||||
}
|
}
|
||||||
|
|
||||||
# Root path serves the photos app
|
# Create special routes for index.html that add script tags
|
||||||
|
handle /index-with-config.html {
|
||||||
|
@is_index_html {
|
||||||
|
path /index-with-config.html
|
||||||
|
}
|
||||||
|
header @is_index_html Content-Type text/html
|
||||||
|
respond @is_index_html 200 {
|
||||||
|
body "<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src=\"/config.js\" type=\"text\/javascript\"></script>
|
||||||
|
<script src=\"/runtime-config.js\" type=\"text\/javascript\"></script>
|
||||||
|
<!-- Placeholder for original head content -->
|
||||||
|
{http.vars.head_content}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{http.vars.body_content}
|
||||||
|
</body>
|
||||||
|
</html>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main photos app - rewrite to use the index-with-config
|
||||||
handle / {
|
handle / {
|
||||||
root * /app/web/photos
|
root * /app/web/photos
|
||||||
try_files {path} /index.html
|
|
||||||
|
# Rewrite index.html to include our config
|
||||||
|
@isroot {
|
||||||
|
path /
|
||||||
|
}
|
||||||
|
|
||||||
|
# For other files just serve them directly
|
||||||
file_server
|
file_server
|
||||||
|
|
||||||
# Dynamically inject our configuration script
|
# Special handling for index.html to inject scripts
|
||||||
header * +Link "</config.js>; rel=preload; as=script"
|
handle @isroot {
|
||||||
header * +Link "</runtime-config.js>; rel=preload; as=script"
|
rewrite * /index-with-config.html
|
||||||
header ?index.html +Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src *"
|
vars {
|
||||||
|
head_content "<!-- Head content from photos app -->"
|
||||||
# Add script injection as HTML filter
|
body_content "<!-- Body content from photos app -->"
|
||||||
filter {
|
}
|
||||||
search_pattern </head>
|
reverse_proxy http://localhost:$CADDY_PORT {
|
||||||
replacement <script src="/config.js" type="text/javascript"></script><script src="/runtime-config.js" type="text/javascript"></script></head>
|
header_up Host {host}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1271,45 +1335,72 @@ cat > /app/data/caddy/Caddyfile <<EOT
|
|||||||
header /_next/static/css/*.css Content-Type text/css
|
header /_next/static/css/*.css Content-Type text/css
|
||||||
|
|
||||||
# Accounts app
|
# Accounts app
|
||||||
handle /accounts/* {
|
handle /accounts {
|
||||||
root * /app/web/accounts
|
header Content-Type text/html
|
||||||
uri strip_prefix /accounts
|
respond 200 {file}/app/data/web/accounts/index.html
|
||||||
try_files {path} /index.html
|
|
||||||
file_server
|
|
||||||
|
|
||||||
# Dynamically inject our configuration script for accounts app
|
|
||||||
filter ?index.html {
|
|
||||||
search_pattern </head>
|
|
||||||
replacement <script src="/config.js" type="text/javascript"></script><script src="/runtime-config.js" type="text/javascript"></script></head>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle /accounts/* {
|
||||||
|
@is_index {
|
||||||
|
path /accounts/
|
||||||
|
path /accounts/index.html
|
||||||
|
}
|
||||||
|
header @is_index Content-Type text/html
|
||||||
|
respond @is_index 200 {file}/app/data/web/accounts/index.html
|
||||||
|
|
||||||
|
@not_index {
|
||||||
|
not path /accounts/
|
||||||
|
not path /accounts/index.html
|
||||||
|
}
|
||||||
|
uri strip_prefix /accounts
|
||||||
|
root @not_index /app/web/accounts
|
||||||
|
file_server @not_index
|
||||||
}
|
}
|
||||||
|
|
||||||
# Auth app
|
# Auth app
|
||||||
handle /auth/* {
|
handle /auth {
|
||||||
root * /app/web/auth
|
header Content-Type text/html
|
||||||
uri strip_prefix /auth
|
respond 200 {file}/app/data/web/auth/index.html
|
||||||
try_files {path} /index.html
|
|
||||||
file_server
|
|
||||||
|
|
||||||
# Dynamically inject our configuration script for auth app
|
|
||||||
filter ?index.html {
|
|
||||||
search_pattern </head>
|
|
||||||
replacement <script src="/config.js" type="text/javascript"></script><script src="/runtime-config.js" type="text/javascript"></script></head>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle /auth/* {
|
||||||
|
@is_index {
|
||||||
|
path /auth/
|
||||||
|
path /auth/index.html
|
||||||
|
}
|
||||||
|
header @is_index Content-Type text/html
|
||||||
|
respond @is_index 200 {file}/app/data/web/auth/index.html
|
||||||
|
|
||||||
|
@not_index {
|
||||||
|
not path /auth/
|
||||||
|
not path /auth/index.html
|
||||||
|
}
|
||||||
|
uri strip_prefix /auth
|
||||||
|
root @not_index /app/web/auth
|
||||||
|
file_server @not_index
|
||||||
}
|
}
|
||||||
|
|
||||||
# Cast app
|
# Cast app
|
||||||
handle /cast/* {
|
handle /cast {
|
||||||
root * /app/web/cast
|
header Content-Type text/html
|
||||||
uri strip_prefix /cast
|
respond 200 {file}/app/data/web/cast/index.html
|
||||||
try_files {path} /index.html
|
|
||||||
file_server
|
|
||||||
|
|
||||||
# Dynamically inject our configuration script for cast app
|
|
||||||
filter ?index.html {
|
|
||||||
search_pattern </head>
|
|
||||||
replacement <script src="/config.js" type="text/javascript"></script><script src="/runtime-config.js" type="text/javascript"></script></head>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle /cast/* {
|
||||||
|
@is_index {
|
||||||
|
path /cast/
|
||||||
|
path /cast/index.html
|
||||||
|
}
|
||||||
|
header @is_index Content-Type text/html
|
||||||
|
respond @is_index 200 {file}/app/data/web/cast/index.html
|
||||||
|
|
||||||
|
@not_index {
|
||||||
|
not path /cast/
|
||||||
|
not path /cast/index.html
|
||||||
|
}
|
||||||
|
uri strip_prefix /cast
|
||||||
|
root @not_index /app/web/cast
|
||||||
|
file_server @not_index
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main API proxy
|
# Main API proxy
|
||||||
@ -1345,8 +1436,7 @@ cat > /app/data/caddy/Caddyfile <<EOT
|
|||||||
}
|
}
|
||||||
EOT
|
EOT
|
||||||
|
|
||||||
echo "==> Created Caddy config with dynamic script injection at /app/data/caddy/Caddyfile"
|
echo "==> Created Caddy config with static HTML files at /app/data/caddy/Caddyfile"
|
||||||
echo "==> No longer trying to modify read-only HTML files"
|
|
||||||
|
|
||||||
# Start Caddy server
|
# Start Caddy server
|
||||||
echo "==> Starting Caddy server"
|
echo "==> Starting Caddy server"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user