Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server could not determine the right service URL inside docker #15

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ services:
- type: bind
source: ~/docker_files/gpodder/data
target: /var/www/server/data
environment:
- gpodder_url=https://gpodder.example.org
hostname: gpodder.example.org
ports:
- 80:80
Expand Down
6 changes: 6 additions & 0 deletions server/inc/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public function __construct(DB $db)
$url .= ':' . $_SERVER['SERVER_PORT'];
}

// Check if environment variable with service url is set
// When running inside Docker, we cannot determine the correct URL by ourselves.
if (getenv('gpodder_url') !== false) {
$url = getenv('gpodder_url');
}

$url .= '/';
$this->base_url = $url;
}
Expand Down
18 changes: 9 additions & 9 deletions server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ function html_head() {
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>' . htmlspecialchars($title) . '</title>
<title>' . htmlspecialchars($title ?? '') . '</title>
<link rel="icon" href="icon.svg" />
</head>

<body>
<h1>' . htmlspecialchars($title) . ' <img src="icon.svg" alt="" /></h1>
<h1>' . htmlspecialchars($title ?? '') . ' <img src="icon.svg" alt="" /></h1>
<main>';
}

Expand All @@ -101,11 +101,11 @@ function html_foot() {

foreach ($gpodder->listActions((int)$_GET['id']) as $row) {
printf('<tr><th>%s</th><td>%s</td><td>%s</td><td><a href="%s">%s</a></td></tr>',
htmlspecialchars($row->action),
htmlspecialchars($row->device),
htmlspecialchars($row->action ?? ''),
htmlspecialchars($row->device ?? ''),
date('d/m/Y H:i', $row->changed),
htmlspecialchars($row->url),
htmlspecialchars(basename($row->url)),
htmlspecialchars($row->url ?? ''),
htmlspecialchars(basename($row->url) ?? ''),
);
}
}
Expand All @@ -115,7 +115,7 @@ function html_foot() {
foreach ($gpodder->listActiveSubscriptions() as $row) {
printf('<tr><th><a href="?id=%d">%s</a></th><td>%s</td><td>%d</td></tr>',
$row->id,
htmlspecialchars($row->url),
htmlspecialchars($row->url ?? ''),
date('d/m/Y H:i', $row->changed),
$row->count
);
Expand Down Expand Up @@ -153,7 +153,7 @@ function html_foot() {
html_head();

if ($error) {
printf('<p class="error center">%s</p>', htmlspecialchars($error));
printf('<p class="error center">%s</p>', htmlspecialchars($error ?? ''));
}

if (isset($_GET['token'])) {
Expand Down Expand Up @@ -188,7 +188,7 @@ function html_foot() {
echo '<p class="error center">Invalid captcha.</p>';
}
elseif ($error = $gpodder->subscribe($_POST['username'] ?? '', $_POST['password'] ?? '')) {
printf('<p class="error center">%s</p>', htmlspecialchars($error));
printf('<p class="error center">%s</p>', htmlspecialchars($error ?? ''));
}
else {
echo '<p class="success">Your account is registered.</p>';
Expand Down