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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maxserver",
3
- "version": "0.8.4",
3
+ "version": "1.0.1",
4
4
  "description": "Node server setup based fastify",
5
5
  "author": "Max Matinpalo",
6
6
  "type": "module",
package/src/devSounds.js CHANGED
@@ -1,31 +1,29 @@
1
- // Development sounds to make api development even more fun 😃
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 === '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
-
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
- const play = file => exec(`afplay "${file}" >/dev/null 2>&1 &`);
13
+ let lastPlayed = 0;
20
14
 
21
- app.addHook('onResponse', async (req, reply) => {
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
- // Dev sounds only for api requests - not for static served files 😃
24
- const ct = String(reply.getHeader('content-type') || '').toLowerCase();
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
- let trigger = ct && ct.includes('application/json') && !disabled;
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 (!app.maxserver.errorLogger) return;
92
+ if (app.maxserver.env !== "development") return;
93
93
 
94
94
  app.addHook("onError", async (req, res, error) => {
95
- console.log("\n‼️ ERROR ‼️");
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
@@ -48,7 +48,7 @@ export async function setupDocs(app) {
48
48
  // operationsSorter: "alpha",
49
49
  orderSchemaPropertiesBy: "preserve",
50
50
  metaData: {
51
- title: "API Docs 👨‍💻",
51
+ title: "Server",
52
52
  },
53
53
  authentication: {
54
54
  preferredSecurityScheme: 'bearerAuth',
@@ -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"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "__NAME__",
3
- "version": "1.0.0",
3
+ "version": "0.1.0",
4
4
  "description": "",
5
5
  "main": "server.js",
6
6
  "scripts": {
@@ -0,0 +1,4 @@
1
+ @node
2
+ @js
3
+ @outjson
4
+ ../
package/templates/ai/BASE DELETED
@@ -1,2 +0,0 @@
1
- @node
2
- @js