maxserver 0.1.17 → 0.1.18

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maxserver",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "Node server setup based fastify",
5
5
  "author": "Max Matinpalo",
6
6
  "type": "module",
@@ -0,0 +1,23 @@
1
+ // Development sounds to make api development even more fun 😃
2
+
3
+
4
+ import { exec } from 'child_process';
5
+
6
+ export async function setupDevSounds(app) {
7
+ if (!app.maxserver.sounds) return;
8
+ if (app.maxserver.env === 'production' || process.env.CI) return;
9
+
10
+ // Using here some builtin macos sounds see file paths
11
+ // For windows we should add alternative
12
+ if (process.platform !== 'darwin') return;
13
+ const ok = '/System/Library/Sounds/Glass.aiff';
14
+ const err = '/System/Library/Sounds/Submarine.aiff';
15
+
16
+ const play = file => exec(`afplay "${file}" >/dev/null 2>&1 &`);
17
+
18
+ app.addHook('onResponse', async (req, reply) => {
19
+ const code = reply.statusCode;
20
+ if (code >= 500) play(err);
21
+ else if (code < 400) play(ok);
22
+ });
23
+ }
package/src/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  import { getAddress } from "./getAddress.js";
14
14
  import { setupDocs } from "./setupDocs.js";
15
15
  import { setupRoutes } from "./setupRoutes.js";
16
-
16
+ import { setupDevSounds } from "./devSounds.js";
17
17
 
18
18
  export default async function maxserver(config = {}) {
19
19
 
@@ -29,6 +29,7 @@ export default async function maxserver(config = {}) {
29
29
  routesDir = process.env.ROUTESDIR || "src",
30
30
  scalar = {},
31
31
  openapiInfo,
32
+ sounds,
32
33
  static: isStatic = process.env.STATIC,
33
34
  public: isPublic = process.env.PUBLIC === "true",
34
35
 
@@ -38,7 +39,7 @@ export default async function maxserver(config = {}) {
38
39
  } = config;
39
40
 
40
41
  const maxserverConfig = {
41
- port, secret, mongodb, docs, cors, env, openapiInfo, routesDir, scalar,
42
+ port, secret, mongodb, docs, cors, env, openapiInfo, routesDir, scalar, sounds,
42
43
  static: isStatic,
43
44
  public: isPublic
44
45
  };
@@ -78,6 +79,7 @@ export default async function maxserver(config = {}) {
78
79
  await setupStatic(app);
79
80
  await setupDocs(app);
80
81
  await setupRoutes(app);
82
+ await setupDevSounds(app);
81
83
 
82
84
  global.createError = function (code, message) {
83
85
  const err = new Error(message);