Skip to content

Commit 1142e60

Browse files
Merge pull request #63 from gchq/release/0.0.10
Release/0.0.10
2 parents 6073a08 + a53b04b commit 1142e60

File tree

6 files changed

+98
-16
lines changed

6 files changed

+98
-16
lines changed

app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import helmet from "helmet";
1212

1313
import bakeRouter from "./routes/bake";
1414
import magicRouter from "./routes/magic";
15+
import healthRouter from "./routes/health.js";
1516

1617
const app = express();
1718
app.disable("x-powered-by");
@@ -41,6 +42,7 @@ app.use(cookieParser());
4142
const swaggerFile = fs.readFileSync("./swagger.yml", "utf8");
4243

4344
// Routes
45+
app.use("/health", healthRouter);
4446
app.use("/bake", bakeRouter);
4547
app.use("/magic", magicRouter);
4648

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cyberchef-server",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "An application providing API access to CyberChef",
55
"author": "d98762625 <[email protected]>",
66
"license": "Apache-2.0",

routes/health.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Router } from "express";
2+
const router = Router();
3+
4+
/**
5+
* bakePost
6+
*/
7+
router.get("/", async function healthGet(req, res, next) {
8+
const healthcheck = {
9+
uptime: process.uptime(),
10+
message: "OK",
11+
timestamp: Date()
12+
};
13+
try {
14+
res.send(healthcheck);
15+
} catch (error) {
16+
healthcheck.message = error;
17+
res.status(503).send();
18+
}
19+
});
20+
21+
export default router;

swagger.yml

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,38 @@ openapi: 3.0.0
22
info:
33
title: CyberChef API
44
description: A HTTP API that exposes some of CyberChef's functionality.
5-
version: 0.0.9
5+
version: 0.0.10
66

77

88
paths:
9+
/health:
10+
get:
11+
summary: Server healthcheck
12+
description: >
13+
If the server is up, returns a 200 response and some basic info about uptime
14+
15+
responses:
16+
'200':
17+
description: Server is alive and healthy
18+
content:
19+
application/json:
20+
schema:
21+
$ref: "#/components/schemas/HealthResponse"
22+
example:
23+
uptime: 1138.00
24+
message: "OK"
25+
timestamp: "Thu Dec 17 2017 19:23:54 GMT+0000"
26+
27+
'503':
28+
description: Server error
29+
content:
30+
application/json:
31+
schema:
32+
$ref: "#/components/schemas/HealthResponse"
33+
example:
34+
uptime: 1138.00
35+
message: "Internal Server Error: Not enough biscuits"
36+
timestamp: "Thu Dec 19 2019 19:23:54 GMT+0000"
937
/bake:
1038
post:
1139
summary: Bakes a recipe
@@ -40,8 +68,7 @@ paths:
4068
content:
4169
application/json:
4270
schema:
43-
type: "string"
44-
value: "Object"
71+
$ref: "#/components/schemas/BakeResponse"
4572
example:
4673
type: "string"
4774
value: "01001110,01111010,01001101,01100111,01001110,01101101,01011001,01100111,01001110,01101101,01010001,01100111,01001110,01101010,01010101,01100111,01001101,01101010,01000001,01100111,01001110,01101010,01101011,01100111,01001110,01101101,01010101,01100111,01001110,01111010,01000001,01100111,01001110,01111010,01010101,01100111,01001110,01111010,01010001,00111101"
@@ -71,9 +98,7 @@ paths:
7198
content:
7299
application/json:
73100
schema:
74-
type: "string"
75-
value:
76-
$ref: "#/components/schemas/MagicResponse"
101+
$ref: "#/components/schemas/MagicResponse"
77102
example:
78103
type: 6
79104
value:
@@ -127,11 +152,12 @@ components:
127152
properties:
128153
op:
129154
type: string
130-
required: true
131155
args:
132156
oneOf:
133157
- $ref: "#/components/schemas/ArgArray"
134158
- $ref: "#/components/schemas/ArgObject"
159+
required:
160+
- op
135161

136162
OperationArray:
137163
type: array
@@ -141,7 +167,7 @@ components:
141167
ArgArray:
142168
type: array
143169
items:
144-
type: {}
170+
type: object
145171
example:
146172
- 16
147173
- true
@@ -154,6 +180,16 @@ components:
154180
upperCaseHex: true
155181
includeFinalLength: false
156182

183+
BakeResponse:
184+
type: object
185+
properties:
186+
type:
187+
type: string
188+
value:
189+
oneOf:
190+
- type: string
191+
- type: number
192+
157193
MagicInput:
158194
type: object
159195
properties:
@@ -166,7 +202,7 @@ components:
166202
type: object
167203
properties:
168204
type:
169-
type: int
205+
type: integer
170206
value:
171207
type: array
172208
items:
@@ -177,16 +213,28 @@ components:
177213
recipe:
178214
type: array
179215
items:
180-
type: Object
216+
type: object
181217
data:
182218
type: string
183219
languageScores:
184220
type: array
185221
items:
186-
type: Object
222+
type: object
187223
matchingOps:
188224
type: array
189225
items:
190-
type: Object
191-
useful: bool
226+
type: object
227+
useful:
228+
type: boolean
229+
230+
HealthResponse:
231+
type: object
232+
properties:
233+
uptime:
234+
type: number
235+
message:
236+
type: string
237+
timestamp:
238+
type: string
239+
192240

test/health.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import request from "supertest";
2+
import app from "../app";
3+
4+
describe("GET /health", function() {
5+
it("should respond with a success response", function(done) {
6+
request(app)
7+
.get("/health")
8+
.set("Accept", "application/json")
9+
.expect(200, done);
10+
});
11+
});

0 commit comments

Comments
 (0)