Skip to content

Commit 3cd5236

Browse files
committed
Removed dependency on Inert when using with Hapi - closes #79
1 parent db51bd4 commit 3cd5236

File tree

11 files changed

+26
-29
lines changed

11 files changed

+26
-29
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ app.use(e2k(swStats.getMiddleware({ swaggerSpec:apiSpec })));
116116
#### Hapi
117117

118118
```javascript
119-
const Inert = require('@hapi/inert');
120119
const swStats = require('swagger-stats');
121120
const swaggerSpec = require('./petstore.json');
122121

@@ -240,6 +239,11 @@ http://<your app host:port>/swagger-stats/ui
240239
241240
## Updates
242241
242+
#### v0.95.9
243+
244+
* [bug] Removed dependency on Inert when using with Hapi [#79](https://github.com/slanatech/swagger-stats/issues/79)
245+
246+
243247
#### v0.95.8
244248
245249
* [feature] Hapijs support [#75](https://github.com/slanatech/swagger-stats/issues/75) - [Example how to use](https://github.com/slanatech/swagger-stats/blob/master/examples/hapijstest/hapijstest.js)

TODO.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

dist/js/sws.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/authtest/authtest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var swaggerSpec = require( specLocation );
6464
// Use swagger-stats middleware with authentication enabled
6565
app.use(swStats.getMiddleware({
6666
name: 'swagger-stats-authtest',
67-
version: '0.95.8',
67+
version: '0.95.9',
6868
hostname: "hostname",
6969
ip: "127.0.0.1",
7070
swaggerSpec:swaggerSpec,

examples/hapijstest/hapijstest.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const Hapi = require('@hapi/hapi');
44
const swStats = require('../../lib'); // require('swagger-stats');
5-
const Inert = require('@hapi/inert');
5+
66

77
const swaggerSpec = require('./petstore.json');
88

@@ -55,11 +55,9 @@ const init = async () => {
5555
}
5656
});
5757

58-
await server.register(Inert);
59-
6058
let swsOptions = {
6159
name: 'swagger-stats-hapitest',
62-
version: '0.95.8',
60+
version: '0.95.9',
6361
hostname: "hostname",
6462
ip: "127.0.0.1",
6563
uriPath: '/swagger-stats',

examples/spectest/spectest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ parser.validate(specLocation,function(err, api) {
7676

7777
var swsOptions = {
7878
name: 'swagger-stats-spectest',
79-
version: '0.95.8',
79+
version: '0.95.9',
8080
hostname: "hostname",
8181
ip: "127.0.0.1",
8282
timelineBucketDuration: tlBucket,

examples/testapp/testapp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ parser.validate(swaggerSpec,function(err, api) {
109109
// Enable swagger-stats middleware
110110
app.use(swStats.getMiddleware({
111111
name: 'swagger-stats-testapp',
112-
version: '0.95.8',
112+
version: '0.95.9',
113113
timelineBucketDuration: tlBucket,
114114
uriPath: '/swagger-stats',
115115
swaggerSpec:swaggerSpec,

lib/sws-api-swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
swagger: '2.0'
22
info:
3-
version: 0.95.8
3+
version: 0.95.9
44
title: swagger-stats API
55
description: |
66
### Telemetry for your APIs

lib/swsHapi.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ const promClient = require("prom-client");
44
const SwsProcessor = require('./swsProcessor');
55
const swsUtil = require('./swsUtil');
66
const debug = require('debug')('sws:hapi');
7-
const Inert = require('@hapi/inert');
7+
//const Inert = require('@hapi/inert');
88
const url = require('url');
99
const qs = require('qs');
10+
const send = require('send');
1011

1112
/* HAPI Plugin */
1213
class SwsHapi {
@@ -103,10 +104,16 @@ class SwsHapi {
103104
server.route({
104105
method: 'GET',
105106
path: this.pathDist+'/{file*}',
106-
handler: {
107-
directory: {
108-
path: path.join(__dirname,'..','dist')
109-
}
107+
handler: function (request, h) {
108+
let fileName = request.params.file;
109+
var options = {
110+
root: path.join(__dirname,'..','dist'),
111+
dotfiles: 'deny'
112+
// TODO Caching
113+
};
114+
request.raw.res.setHeader('Content-Type', send.mime.lookup(path.basename(fileName)));
115+
send(request.raw.req, fileName, options).pipe(request.raw.res);
116+
return h.abandon;
110117
}
111118
})
112119
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-stats",
3-
"version": "0.95.8",
3+
"version": "0.95.9",
44
"description": "API Telemetry and APM. Trace API calls and Monitor API performance, health and usage statistics in Node.js Microservices, based on express routes and Swagger (Open API) specification",
55
"main": "lib/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)