maxserver 0.1.23 → 0.1.29

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/bin/init.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maxserver",
3
- "version": "0.1.23",
3
+ "version": "0.1.29",
4
4
  "description": "Node server setup based fastify",
5
5
  "author": "Max Matinpalo",
6
6
  "type": "module",
package/src/devSounds.js CHANGED
@@ -20,9 +20,15 @@ export async function setupDevSounds(app) {
20
20
 
21
21
  app.addHook('onResponse', async (req, reply) => {
22
22
 
23
- // Test fix, that sound not plays for static served 😃
23
+ // Dev sounds only for api requests - not for static served files 😃
24
24
  const ct = String(reply.getHeader('content-type') || '').toLowerCase();
25
- if (ct && ct.includes('application/json')) {
25
+ const disabled = req.routeOptions?.config?.devSound === false;
26
+ let trigger = ct && ct.includes('application/json') && !disabled;
27
+
28
+ // Though this is route is auto registered by scalar, and we can't set sounds false on it...
29
+ if (req.url === "/docs/openapi.json") return;
30
+
31
+ if (trigger) {
26
32
  const code = reply.statusCode;
27
33
  if (code < 400) play(ok);
28
34
  else play(err);
package/src/index.js CHANGED
@@ -17,6 +17,8 @@ import { setupDevSounds } from "./devSounds.js";
17
17
 
18
18
  export default async function maxserver(config = {}) {
19
19
 
20
+ console.log("local one running 3");
21
+
20
22
  const {
21
23
 
22
24
  // maxserver options
@@ -71,6 +73,7 @@ export default async function maxserver(config = {}) {
71
73
  console.log('Server running at ', getAddress(this));
72
74
  });
73
75
 
76
+ await setupDevSounds(app);
74
77
  await setupCookie(app);
75
78
  await setupHelmet(app);
76
79
  await setupCors(app);
@@ -79,7 +82,7 @@ export default async function maxserver(config = {}) {
79
82
  await setupStatic(app);
80
83
  await setupDocs(app);
81
84
  await setupRoutes(app);
82
- await setupDevSounds(app);
85
+
83
86
 
84
87
  global.createError = function (code, message) {
85
88
  const err = new Error(message);
package/src/setupDocs.js CHANGED
@@ -2,7 +2,7 @@ import swagger from "@fastify/swagger";
2
2
  import apiReference from "@scalar/fastify-api-reference";
3
3
 
4
4
 
5
-
5
+ /*
6
6
  const schema = {
7
7
  summary: "OpenAPI Specification",
8
8
  description: "Returns the full OpenAPI 3.0 specification.",
@@ -27,6 +27,7 @@ const schema = {
27
27
  }
28
28
  }
29
29
  };
30
+ */
30
31
 
31
32
 
32
33
 
@@ -53,8 +54,9 @@ export async function setupDocs(app) {
53
54
  },
54
55
  });
55
56
 
57
+ // not needed, the scalar extension provides it by default on /docs/openapi.json
58
+ // app.get("/openapi.json", {schema}, () => app.swagger());
56
59
 
57
- app.get("/openapi.json", { schema }, () => app.swagger());
58
60
 
59
61
  if (app.maxserver.docs !== false)
60
62
  await app.register(apiReference, {
@@ -67,6 +69,7 @@ export async function setupDocs(app) {
67
69
  telemetry: false,
68
70
  persistAuth: true,
69
71
  showDeveloperTools: "never",
72
+ //"expandAllModelSections": true,
70
73
  operationsSorter: "alpha",
71
74
  orderSchemaPropertiesBy: "preserve",
72
75
  metaData: {
@@ -65,23 +65,6 @@ export async function setupRoutes(app) {
65
65
  const root = path.resolve(app.maxserver.routesDir || "src");
66
66
  const files = walk(root);
67
67
 
68
- /*
69
- // Old one which only graps default exports
70
-
71
- // 1. Pass One: Register Global Schemas (Lonely .schema.js files)
72
- for (const file of files) {
73
- if (file.endsWith(".schema.js")) {
74
- const hasHandler = fs.existsSync(file.replace(".schema.js", ".js"));
75
-
76
- if (!hasHandler) {
77
- const schema = await importDefault(file);
78
- if (schema?.$id) app.addSchema(schema);
79
- }
80
- }
81
- }
82
- */
83
-
84
-
85
68
  // 1. Pass One: Register Global Schemas (Lonely .schema.js files)
86
69
  for (const file of files) {
87
70
  // Only process if no matching handler file exists
@@ -94,7 +77,14 @@ export async function setupRoutes(app) {
94
77
  }
95
78
  }
96
79
 
97
- // 2. Pass Two: Register Routes
80
+ // 2. Pass Two: Auto-register hooks
81
+ for (const file of files) {
82
+ const mod = await import(pathToFileURL(file).href);
83
+ for (const [key, fn] of Object.entries(mod))
84
+ if (key.startsWith("autoregister_") && typeof fn === "function") await fn(app);
85
+ }
86
+
87
+ // 3. Pass Three: Register Routes
98
88
  const seen = new Map();
99
89
  for (const file of files) {
100
90
  if (file.endsWith(".schema.js")) continue;
package/TODO.md DELETED
@@ -1,4 +0,0 @@
1
- - get rules.md file for ai (lost atm)
2
- - add example for db usage
3
- - unity tests for each config option
4
-