Skip to content

Commit

Permalink
feat: Add hostname to response data in API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
qjoly committed Nov 1, 2024
1 parent a4f2537 commit 59707c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion micro-service/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
// Generate a random number between 0 and 10
$random_number = rand(0, 10);

// Get the hostname of the server
$hostname = gethostname();

// Create an array with the random number
$response_data = array(
'number' => $random_number
'number' => $random_number,
'hostname' => $hostname
);

// Set the content type to JSON
Expand Down
7 changes: 7 additions & 0 deletions micro-service/frontend/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@

<footer style="padding-top: 10px">
<div class="ip-hostname">

<?php
if (isset($json_data['hostname'])) {
echo "<i>Response from : " . $json_data['hostname'] . "</i>";
}
?>

<p>IP Address:
<?php echo getenv('POD_IP') ?: $_SERVER['SERVER_ADDR']; ?>
</p>
Expand Down

0 comments on commit 59707c3

Please sign in to comment.