Cscott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/159183

Change subject: Add a human-readable help page to quickly test/check the 
service.
......................................................................

Add a human-readable help page to quickly test/check the service.

Change-Id: I7b6577387ac9ab57e16b63bc7001ce6437855012
---
M lib/threads/frontend.js
A lib/threads/help.html
2 files changed, 70 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Collection/OfflineContentGenerator
 refs/changes/83/159183/1

diff --git a/lib/threads/frontend.js b/lib/threads/frontend.js
index 38cb3e1..ac9ebb4 100644
--- a/lib/threads/frontend.js
+++ b/lib/threads/frontend.js
@@ -200,6 +200,13 @@
 
                } else if ( request.method === 'GET' ) {
                        args = url.parse( request.url, true ).query;
+                       // handle two special paths:
+                       // the favicon, and the top-level help page
+                       if ( request.url === '/' ) {
+                               args = { command: 'help' };
+                       } else if ( request.url === '/favicon.ico' ) {
+                               args = { command: 'favicon' };
+                       }
                        resolve( args );
 
                } else {
@@ -271,8 +278,12 @@
        statsd.increment( 'frontend.requests.' + args.command );
 
        switch ( args.command ) {
+               case 'favicon':
+                       return handleFavicon( requestId, args, response );
                case 'health':
                        return handleHealthCheck( requestId, args, response );
+               case 'help':
+                       return handleHelp( requestId, args, response );
                case 'render':
                        return handleRender( requestId, args, response );
                case 'render_status':
@@ -285,6 +296,30 @@
 }
 
 /**
+ * Don't pollute the logs with favicon requests.
+ */
+function handleFavicon( requestId, args, response ) {
+       return Promise.resolve().then(function() {
+               response.writeHead( 404, "No favicon implemented" );
+               response.end();
+       });
+}
+
+/**
+ * Return a friendly help page.
+ */
+function handleHelp( requestId, args, response ) {
+       return Promise.promisify( fs.readFile, false, fs )(
+               path.join( __dirname, 'help.html' ), 'utf-8'
+       ).then(function(helpfile) {
+               response.writeHead(200, {
+                       'Content-Type': 'text/html'
+               });
+               response.end(helpfile, 'utf8');
+       });
+}
+
+/**
  * Return health parameters, we're OK if the frontend is responsive
  * but we also want to know the length of the queue
  *
diff --git a/lib/threads/help.html b/lib/threads/help.html
new file mode 100644
index 0000000..828ba76
--- /dev/null
+++ b/lib/threads/help.html
@@ -0,0 +1,35 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>OCG Render Service</title>
+</head>
+
+<body>
+<h1>Offline Content Generator Render Service</h1>
+
+For more details, see the
+<a 
href="https://github.com/wikimedia/mediawiki-extensions-Collection-OfflineContentGenerator#readme";>README
 for this service at github</a>.
+
+<h2>Maintenance commands</h2>
+<h3>health</h3>
+<form>
+<input type=hidden name=command value=health>
+<input type=submit value="Make Health Request">
+</form>
+
+<h3>render</h3>
+<form>
+<p>Collection Id: <input type=text name="collection_id" /></p>
+<p>Writer: <input type=text name="writer" /></p>
+<input type=submit name="command" value="render">
+</form>
+
+<h3>render_status/download</h3>
+<form>
+<p>Collection Id: <input type=text name="collection_id" /></p>
+<input type=submit name="command" value="render_status">
+<input type=submit name="command" value="download">
+</form>
+
+</body>
+</html>

-- 
To view, visit https://gerrit.wikimedia.org/r/159183
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7b6577387ac9ab57e16b63bc7001ce6437855012
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Collection/OfflineContentGenerator
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to