simple-http-bin 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +9 -0
  2. package/cli.js +10 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -49,3 +49,12 @@ curl http://127.0.0.1:51234/headers
49
49
  curl -X POST http://127.0.0.1:51234/anything -d "hello"
50
50
  curl -i http://127.0.0.1:51234/status/418
51
51
  ```
52
+
53
+ ## Release
54
+
55
+ ```bash
56
+ make release-patch
57
+ make release-minor
58
+ make release-major
59
+ make publish
60
+ ```
package/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const http = require('node:http');
4
4
  const chalk = require('chalk');
5
+ const { version } = require('./package.json');
5
6
 
6
7
  const DEFAULT_PORT = 51234;
7
8
  const args = process.argv.slice(2);
@@ -48,6 +49,10 @@ const colors = {
48
49
  title: chalk.green.bold,
49
50
  };
50
51
 
52
+ function requestSeparator() {
53
+ return colors.meta('='.repeat(72));
54
+ }
55
+
51
56
  function sendJson(res, statusCode, payload) {
52
57
  const body = JSON.stringify(payload, null, 2);
53
58
  res.writeHead(statusCode, {
@@ -77,15 +82,18 @@ function logRequest(req, res, path, startedAt, details = {}) {
77
82
  const baseLine = `${colors.method(req.method)} ${colors.path(path)} ${colors.meta('->')} ${statusText} ${colors.dim(`(${durationMs}ms)`)}`;
78
83
 
79
84
  if (logLevel === 1) {
85
+ console.log(requestSeparator());
80
86
  console.log(baseLine);
81
87
  return;
82
88
  }
83
89
 
84
90
  if (logLevel === 2) {
91
+ console.log(requestSeparator());
85
92
  console.log(`${baseLine} ${colors.meta('from')} ${colors.meta(`${remoteAddress}:${remotePort}`)} ${colors.meta('ua=')}${chalk.white(JSON.stringify(userAgent))}`);
86
93
  return;
87
94
  }
88
95
 
96
+ console.log(requestSeparator());
89
97
  console.log([
90
98
  `${baseLine} ${colors.meta('from')} ${colors.meta(`${remoteAddress}:${remotePort}`)}`,
91
99
  `${colors.meta('ua=')}${chalk.white(JSON.stringify(userAgent))}`,
@@ -97,9 +105,10 @@ function logRequest(req, res, path, startedAt, details = {}) {
97
105
 
98
106
  function helpText(baseUrl) {
99
107
  return [
100
- colors.title('simple-http-bin'),
108
+ colors.title(`simple-http-bin v${version}`),
101
109
  '',
102
110
  `${colors.meta('Running at:')} ${chalk.white(baseUrl)}`,
111
+ `${colors.meta('Version:')} ${chalk.white(version)}`,
103
112
  `Port: ${port} (use --port <n> or PORT=<n>)`,
104
113
  'Requests are logged to the console.',
105
114
  'Use -v or --verbose for more detail; repeat -v for even more.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-http-bin",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "A tiny local httpbin-like utility",
5
5
  "license": "MIT",
6
6
  "keywords": [