Skip to content

Commit

Permalink
chore(release): 2.2.0 [skip ci]
Browse files Browse the repository at this point in the history
# [2.2.0](v2.1.1...v2.2.0) (2022-07-14)

### Features

* add har support ([f1bee8c](f1bee8c))
  • Loading branch information
semantic-release-bot committed Jul 14, 2022
1 parent f1bee8c commit 0a02c93
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [2.2.0](https://github.com/ClearC2/headlamp/compare/v2.1.1...v2.2.0) (2022-07-14)


### Features

* add har support ([f1bee8c](https://github.com/ClearC2/headlamp/commit/f1bee8c0557bef15ba36a2124a68b7c67b32be0b))

## [2.1.1](https://github.com/ClearC2/headlamp/compare/v2.1.0...v2.1.1) (2020-11-24)


Expand Down
2 changes: 1 addition & 1 deletion api-explorer-dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Headlamp</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link href="/_docs/1.5fa7fc7921140c03d4d2.css" rel="stylesheet"><link href="/_docs/main.8d67c61bfa4e2256cb5d.css" rel="stylesheet"></head>
<link href="/_docs/1.4fb97a2386cda86082bf.css" rel="stylesheet"><link href="/_docs/main.8d67c61bfa4e2256cb5d.css" rel="stylesheet"></head>
<body>
<div id="app-root"></div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
Expand Down
2 changes: 1 addition & 1 deletion api-explorer-dist/main.js

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions api-explorer-dist/vendors~main.js

Large diffs are not rendered by default.

57 changes: 56 additions & 1 deletion lib/api-route-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,41 @@ var execSync = _child_process["default"].execSync;

function _default(app) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// HAR support
var har = null; // to keep track of the sequence of requests

var harState = {};
app.use(function (req, res, next) {
var _har, _har2;

var harRoutes = ((_har = har) === null || _har === void 0 ? void 0 : _har.requests) || [];
var incomingPath = ((_har2 = har) === null || _har2 === void 0 ? void 0 : _har2.matchQuery) ? req.originalUrl : req.path;
var matchingRequests = harRoutes.filter(function (r) {
var _har3;

var compareUrl = r.path;

if ((_har3 = har) === null || _har3 === void 0 ? void 0 : _har3.matchQuery) {
var url = new URL(r.request.url);
compareUrl = "".concat(url.pathname).concat(url.search);
}

return compareUrl === incomingPath && r.method === req.method;
});
harState[incomingPath] = harState[incomingPath] || 0;
var requestIndex = harState[incomingPath];
var matchingRequest = matchingRequests[requestIndex];

if (matchingRequest) {
// increase the sequence to be ready for the next request
++harState[incomingPath];
res.set('X-Headlamp-HAR-response-sequence', requestIndex + 1);
res.set('X-Headlamp-HAR-matching-responses', matchingRequests.length);
return res.status(matchingRequest.response.status).json(matchingRequest.json);
}

next();
});
var responseStore = createActivationStore();
var customResponseStore = createCustomResponseStore();

Expand Down Expand Up @@ -126,7 +161,8 @@ function _default(app) {
title: options.title,
description: options.description,
hidePath: options.hidePath,
src: options.src
src: options.src,
har: har
});
});
app.get('/_grep', function (req, res) {
Expand Down Expand Up @@ -370,6 +406,25 @@ function _default(app) {
return res.json({
message: 'Deleted'
});
});
app.post('/_har', function (req, res) {
har = req.body.har;
harState = {};
return res.json({
message: 'Success'
});
});
app.get('/_har', function (req, res) {
return res.json({
har: har
});
});
app["delete"]('/_har', function (req, res) {
har = null;
harState = {};
return res.json({
message: 'Success'
});
}); // serve the api explorer

app.use('/_docs', _express["default"]["static"](_path["default"].resolve(__dirname, '..', 'api-explorer-dist'))); // fallback to serve the api explorer so /_docs/request/* will work
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clearc2/headlamp",
"version": "2.1.1",
"version": "2.2.0",
"description": "Express API documenter",
"main": "lib/index.js",
"publishConfig": {
Expand Down

0 comments on commit 0a02c93

Please sign in to comment.