maxserver 0.8.4 → 1.0.1
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 +1 -1
- package/src/devSounds.js +17 -19
- package/src/index.js +2 -4
- package/src/setup.js +2 -2
- package/src/setupDocs.js +1 -1
- package/templates/jsconfig.json +0 -8
- package/templates/package.json +1 -1
- package/templates/src/ai/BASE +4 -0
- package/templates/ai/BASE +0 -2
package/package.json
CHANGED
package/src/devSounds.js
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
// Development sounds
|
|
1
|
+
// Development sounds to make api development even more fun 😃
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import { exec } from 'child_process';
|
|
3
|
+
import { exec } from "child_process";
|
|
5
4
|
|
|
6
5
|
export async function setupDevSounds(app) {
|
|
7
6
|
if (!app.maxserver.sounds) return;
|
|
8
|
-
if (app.maxserver.env
|
|
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
|
-
|
|
7
|
+
if (app.maxserver.env !== "development" || process.env.CI) return;
|
|
8
|
+
if (process.platform !== "darwin") return;
|
|
17
9
|
|
|
10
|
+
const ok = "/System/Library/Sounds/Glass.aiff";
|
|
11
|
+
const err = "/System/Library/Sounds/Submarine.aiff";
|
|
18
12
|
|
|
19
|
-
|
|
13
|
+
let lastPlayed = 0;
|
|
20
14
|
|
|
21
|
-
|
|
15
|
+
const play = file => {
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
if (now - lastPlayed < 1000) return;
|
|
18
|
+
lastPlayed = now;
|
|
19
|
+
exec(`afplay "${file}" >/dev/null 2>&1 &`);
|
|
20
|
+
};
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
const ct = String(reply.getHeader(
|
|
22
|
+
app.addHook("onResponse", async (req, reply) => {
|
|
23
|
+
const ct = String(reply.getHeader("content-type") || "").toLowerCase();
|
|
25
24
|
const disabled = req.routeOptions?.config?.devSound === false;
|
|
26
|
-
|
|
25
|
+
const trigger = ct && ct.includes("application/json") && !disabled;
|
|
27
26
|
|
|
28
|
-
// Though this is route is auto registered by scalar, and we can't set sounds false on it...
|
|
29
27
|
if (req.url === "/docs/openapi.json") return;
|
|
30
28
|
|
|
31
29
|
if (trigger) {
|
|
@@ -34,4 +32,4 @@ export async function setupDevSounds(app) {
|
|
|
34
32
|
else play(err);
|
|
35
33
|
}
|
|
36
34
|
});
|
|
37
|
-
}
|
|
35
|
+
}
|
package/src/index.js
CHANGED
|
@@ -28,10 +28,9 @@ export default async function maxserver(config = {}) {
|
|
|
28
28
|
routesDir = process.env.ROUTESDIR || "src",
|
|
29
29
|
scalar = {},
|
|
30
30
|
openapiInfo,
|
|
31
|
-
sounds,
|
|
31
|
+
sounds = true,
|
|
32
32
|
static: isStatic = process.env.STATIC,
|
|
33
33
|
public: isPublic = process.env.PUBLIC === "true",
|
|
34
|
-
errorLogger = process.env.ERROR_LOGGER === "true",
|
|
35
34
|
|
|
36
35
|
...fastifyOpts
|
|
37
36
|
} = config;
|
|
@@ -45,8 +44,7 @@ export default async function maxserver(config = {}) {
|
|
|
45
44
|
const maxserverConfig = {
|
|
46
45
|
port, secret, mongodb, docs, cors, env, openapiInfo, routesDir, scalar, sounds,
|
|
47
46
|
static: isStatic,
|
|
48
|
-
public: isPublic
|
|
49
|
-
errorLogger
|
|
47
|
+
public: isPublic
|
|
50
48
|
};
|
|
51
49
|
|
|
52
50
|
if (!secret) throw new Error("secret is must have");
|
package/src/setup.js
CHANGED
|
@@ -89,10 +89,10 @@ export async function setupStatic(app) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
export async function setupErrorLogger(app) {
|
|
92
|
-
if (
|
|
92
|
+
if (app.maxserver.env !== "development") return;
|
|
93
93
|
|
|
94
94
|
app.addHook("onError", async (req, res, error) => {
|
|
95
|
-
console.log("\n
|
|
95
|
+
console.log("\n\x1b[1;31mERROR\x1b[0m");
|
|
96
96
|
|
|
97
97
|
const stackLine = error.stack.split("\n")[1];
|
|
98
98
|
const match = stackLine.match(/([^\s()]+):(\d+):\d+/);
|
package/src/setupDocs.js
CHANGED
package/templates/jsconfig.json
CHANGED
|
@@ -4,19 +4,11 @@
|
|
|
4
4
|
"module": "ES2020",
|
|
5
5
|
"target": "ES2020",
|
|
6
6
|
"moduleResolution": "bundler",
|
|
7
|
-
"jsx": "react-jsx",
|
|
8
7
|
"strict": false,
|
|
9
8
|
"noUnusedParameters": false,
|
|
10
9
|
"noUnusedLocals": false,
|
|
11
10
|
"noImplicitAny": false,
|
|
12
|
-
// new attempt to reduce noise
|
|
13
11
|
"skipLibCheck": true,
|
|
14
|
-
//"baseUrl": ".",
|
|
15
|
-
"paths": {
|
|
16
|
-
"*": [
|
|
17
|
-
"./src/*"
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
12
|
"types": [
|
|
21
13
|
"node",
|
|
22
14
|
"maxserver"
|
package/templates/package.json
CHANGED
package/templates/ai/BASE
DELETED