Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Bug 527304 - Implement the /about and /whoami endpoints - about endpoint
- Loading branch information
Showing
4 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2016, 2017 IBM Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License v1.0 | ||
| * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution | ||
| * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
| /*eslint-env node */ | ||
| var express = require('express'), | ||
| api = require('./api'), | ||
| responseTime = require('response-time'), | ||
| pjson = require('../package.json'); | ||
|
|
||
| var XHTML_1 = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<title>", | ||
| XHTML_2 = "</title>\n <style type = \"text/css\"> td { padding-right : 10px; }</style></head>\n<body>\n", | ||
| XHTML_3 = "</body>\n</html>", | ||
| BUILD_ID = "unknown"; | ||
|
|
||
| class About { | ||
| /** | ||
| * @description Create a new instance of the class | ||
| */ | ||
| constructor() { | ||
|
|
||
| } | ||
| /** | ||
| * @description Create an express Router for handling /about | ||
| * @param {?} options The map of options. Must contain the configParams property | ||
| * @returns {Router} A new express router for handling /about | ||
| * @throws {Error} If options.configParams is not defined | ||
| * @since 17.0 | ||
| */ | ||
| createRouter(options) { | ||
| var configParams = options.configParams; | ||
| if (!configParams) { | ||
| throw new Error('options.configParams is required'); | ||
| } | ||
| return express.Router() | ||
| .use(responseTime({digits: 2, header: "X-About-Response-Time", suffix: true})) | ||
| .get('*', /* @callback */ function (req, res) { | ||
| var about = String(XHTML_1).concat("About").concat(XHTML_2); | ||
| var buildID = configParams["orion.buildId"] || BUILD_ID; | ||
| if(buildID === "unknown" && pjson && typeof pjson.version === 'string') { | ||
| //for the NPM case we want to return the version published to NPM (from the package.json) | ||
| buildID = pjson.version; | ||
| } | ||
| about = about.concat("<table><tr><td><img src=\"../webapp/orion-96.png\"/></td><td><p>"); | ||
| about = about.concat("Build Id: " + buildID + "<br/></p></td></tr></table>"); | ||
| about = about.concat("<table>"); | ||
| about = about.concat("<tr><th align=\"left\">Library</th><th align=\"center\">Version</th></tr>"); | ||
| if(pjson.dependencies) { | ||
| Object.keys(pjson.dependencies).forEach(function(key) { | ||
| about = about.concat("<tr><td align=\"left\">"+key+"</td><td align=\"center\">"+pjson.dependencies[key]+"</td></tr>"); | ||
| }); | ||
| } | ||
| about = about.concat("</table>").concat(XHTML_3); | ||
| res.contentType('html'); | ||
| return api.writeResponse(200, res, null, about); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| module.exports.About = About; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2017 IBM Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License v1.0 | ||
| * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution | ||
| * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
| /*eslint-env mocha */ | ||
| var assert = require('assert'), | ||
| testData = require("../support/test_data"), | ||
| testHelper = require('../support/testHelper'); | ||
|
|
||
| var CONTEXT_PATH = testHelper.CONTEXT_PATH, | ||
| PREFIX = CONTEXT_PATH + '/about'; | ||
|
|
||
| var request = testData.setupOrionServer(); | ||
|
|
||
| describe("About endpoint", function() { | ||
| it("testAbout", function(done) { | ||
| request() | ||
| .get(PREFIX) | ||
| .expect(200) | ||
| .end(function(err, res) { | ||
| testHelper.throwIfError(err); | ||
| assert(res.body, "There sould be a body in the response."); | ||
| done(); | ||
| }); | ||
| }); | ||
| it("testAbout/about", function(done) { | ||
| request() | ||
| .get(PREFIX+PREFIX) | ||
| .expect(200) | ||
| .end(function(err, res) { | ||
| testHelper.throwIfError(err); | ||
| assert(res.body, "There sould be a body in the response."); | ||
| done(); | ||
| }); | ||
| }); | ||
| it("testAbout.html", function(done) { | ||
| request() | ||
| .get(PREFIX+'.html') | ||
| .expect(404, done); | ||
| }); | ||
| it("testAbout/about.html", function(done) { | ||
| request() | ||
| .get(PREFIX+PREFIX+'/html') | ||
| .expect(200) | ||
| .end(function(err, res) { | ||
| testHelper.throwIfError(err); | ||
| assert(res.body, "There sould be a body in the response."); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2017 IBM Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License v1.0 | ||
| * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution | ||
| * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). | ||
| * | ||
| * Contributors: | ||
| * IBM Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
| /*eslint-env mocha */ | ||
| var assert = require('assert'), | ||
| testData = require("../support/test_data"), | ||
| testHelper = require('../support/testHelper'); | ||
|
|
||
| var CONTEXT_PATH = testHelper.CONTEXT_PATH, | ||
| PREFIX = CONTEXT_PATH + '/version'; | ||
|
|
||
| var request = testData.setupOrionServer(); | ||
|
|
||
| describe("Version endpoint", function() { | ||
| it("testVersion", function(done) { | ||
| request() | ||
| .get(PREFIX) | ||
| .expect(200) | ||
| .end(function(err, res) { | ||
| testHelper.throwIfError(err); | ||
| assert(res.body, "There sould be a body in the response."); | ||
| assert(res.body.build, "There should be a build in the body;"); | ||
| done(); | ||
| }); | ||
| }); | ||
| it("testVersion/version", function(done) { | ||
| request() | ||
| .get(PREFIX+PREFIX) | ||
| .expect(200) | ||
| .end(function(err, res) { | ||
| testHelper.throwIfError(err); | ||
| assert(res.body, "There sould be a body in the response."); | ||
| assert(res.body.build, "There should be a build in the body;"); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); |