Skip to content

Commit

Permalink
Add ping resource and test
Browse files Browse the repository at this point in the history
* Add ping resource and test
* Adding charset to /ping
* Set cache-control explicitly
  • Loading branch information
nlisgo committed Mar 28, 2017
1 parent ee8bb27 commit e2a6959
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions smoke_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -ex
local_hostname=$(hostname)
hostname=${1:-$local_hostname}

echo "Ping"
[ $(curl --write-out %{http_code} --silent --output /dev/null "${hostname}/ping") == 200 ]

echo "Homepage"
[ $(curl --write-out %{http_code} --silent --output /dev/null "$hostname") == 200 ]

Expand Down
5 changes: 5 additions & 0 deletions src/modules/jcms_ping/jcms_ping.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Journal CMS (Ping)
type: module
description: Check to see the site is up
core: 8.x
package: Journal CMS
8 changes: 8 additions & 0 deletions src/modules/jcms_ping/jcms_ping.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
jcms_ping.check.json:
path: '/ping'
defaults:
_controller: \Drupal\jcms_ping\Controller\PingController::siteStatus
options:
no_cache: TRUE
requirements:
_access: 'TRUE'
32 changes: 32 additions & 0 deletions src/modules/jcms_ping/src/Controller/PingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Drupal\jcms_ping\Controller;

use Symfony\Component\HttpFoundation\Response;

/**
* Controller to handle a ping request for journal-cms.
*/
class PingController {

/**
* String sent in responses, to verify site status.
*
* @var string
*/
const SITE_STATUS_RESPONSE = 'pong';

/**
* Checks the site status.
*
* @return \Symfony\Component\HttpFoundation\Response
* The response.
*/
public function siteStatus() {
$response = new Response(self::SITE_STATUS_RESPONSE);
$response->headers->set('Content-Type', 'text/plain; charset=UTF-8');
$response->headers->set('Cache-Control', 'must-revalidate, no-cache, no-store, private');
return $response;
}

}
1 change: 1 addition & 0 deletions sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module:
jcms_article_fragment: 0
jcms_migrate: 0
jcms_notifications: 0
jcms_ping: 0
jcms_rest: 0
jsonb: 0
link: 0
Expand Down

0 comments on commit e2a6959

Please sign in to comment.