Skip to content

Commit

Permalink
mini docs
Browse files Browse the repository at this point in the history
  • Loading branch information
radenkovic committed Aug 16, 2020
1 parent f401d59 commit 5fcd316
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
95 changes: 93 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,95 @@ Debug FeathersJS API requests, find bottlenecks, read payloads and understand ho

> Extension to debug [FeathersJS](https://github.com/feathersjs/feathers) server.
![sample image](https://raw.githubusercontent.com/radenkovic/feathers-debugger/master/docs/screenshot.png)
![sample image](https://raw.githubusercontent.com/radenkovic/feathers-debugger/master/docs/sample.gif)


## Usage

> This plugin is still in active development.

1. Install chrome extension

2. Add hook

Note: this will be npm package. For now you can install it manually.


Create hook that will write file `feathers-debugger` to public folder.

```js
// feathers-debugger.js
const fs = require('fs');
const path = require('path');

const PUBLIC_PATH = 'public';

// Remove file on every server start
try {
const stats = fs.statSync(path.join(PUBLIC_PATH, '/feathers-debugger'));
if (stats['size'] > 2000000) {
// Delete file if it's too large
fs.unlinkSync(path.join(PUBLIC_PATH, '/feathers-debugger'));
}
} catch (e) {
// NO_OP
}

// Stream to write file
const writer = fs.createWriteStream(
path.join(PUBLIC_PATH, '/feathers-debugger'),
{ flags: 'a' }
);

module.exports = () => (ctx) => {
if (!ctx._req_ts) {
ctx._req_ts = Date.now();
} else {
ctx._req_duration = Date.now() - ctx._req_ts;
}
const payload = {
id: ctx._req_id,
path: ctx.path,
type: ctx.type,
method: ctx.method,
provider: ctx.params ? ctx.params.provider : undefined,
ts: ctx._req_ts,
duration: ctx._req_duration,
end: Date.now(),
};
if (payload.duration) {
writer.write(JSON.stringify(payload) + '\n');
}
};


```

3. Include that hook in `app.hooks.js`:

```js
// app.hooks
const feathersDebugger = require('./feathers-debugger')

module.exports = {
before: {
all: [
feathersDebugger(),
],
// ....
finally: {
all: [
feathersDebugger()
]
}
```
4. (optional) gitignore `public/feathers-debugger`
5. Open devtools and click "Feathers" tab
Happy debugging!
Expand All @@ -14,4 +102,7 @@ Debug FeathersJS API requests, find bottlenecks, read payloads and understand ho
- git clone https://github.com/radenkovic/feathers-debugger
- yarn
- yarn dev
- open [localhost:3000/devtools.html](http://localhost:3000/devtools.html)
- open [localhost:3000/devtools.html](http://localhost:3000/devtools.html)
Binary file added docs/sample.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/index.html",
"scripts": {
"dev": "parcel src/devtools.html --out-file devtools.html src/popup.html --port 3000",
"build": "export NODE_ENV=production && parcel --no-source-maps --out-file devtools.html build src/index.html src/popup.html"
"build": "export NODE_ENV=production && parcel --no-source-maps build src/devtools.html src/popup.html"
},
"keywords": ["feathers", "feathersjs", "feathers-debugger", "chrome", "extension"],
"author": "Dan Radenkovic",
Expand Down

0 comments on commit 5fcd316

Please sign in to comment.