maxserver 0.2.4 → 0.2.6

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/watcher.js CHANGED
@@ -29,7 +29,7 @@ function start() {
29
29
 
30
30
  function restart() {
31
31
  console.clear();
32
- console.log(`devserver restart`);
32
+ //console.log(`devserver restart`);
33
33
  if (child) child.kill();
34
34
  start();
35
35
  }
@@ -41,7 +41,7 @@ fs.watch(".", { recursive: true }, (event, file) => {
41
41
  if (file.startsWith(".")) return;
42
42
  if (!file.endsWith(".js") && !file.endsWith(".json")) return;
43
43
 
44
- console.log("\nupdated: ", file);
44
+ //console.log("\nupdated: ", file);
45
45
  restart();
46
46
  });
47
47
 
package/index.d.ts CHANGED
@@ -9,7 +9,7 @@ declare global {
9
9
  var global: typeof globalThis;
10
10
 
11
11
  /** Casts a string ID to a MongoDB ObjectId using the global helper [cite: 2026-02-15]. */
12
- var oid: (id: string) => import("mongodb").ObjectId;
12
+ var oid: (id?: string) => import("mongodb").ObjectId;
13
13
 
14
14
  /** Access to the global MongoDB database instance [cite: 2026-02-15]. */
15
15
  var db: import("mongodb").Db;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maxserver",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Node server setup based fastify",
5
5
  "author": "Max Matinpalo",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -15,6 +15,9 @@ import { setupDocs } from "./setupDocs.js";
15
15
  import { setupRoutes } from "./setupRoutes.js";
16
16
  import { setupDevSounds } from "./devSounds.js";
17
17
 
18
+
19
+
20
+
18
21
  export default async function maxserver(config = {}) {
19
22
 
20
23
 
@@ -26,7 +29,7 @@ export default async function maxserver(config = {}) {
26
29
  mongodb = process.env.MONGODB,
27
30
  docs = process.env.DOCS !== "false",
28
31
  cors = process.env.CORS || "*",
29
- env = process.env.NODE_ENV || "development",
32
+ env = process.env.NODE_ENV || "development", // should be removed, define via env only
30
33
  routesDir = process.env.ROUTESDIR || "src",
31
34
  scalar = {},
32
35
  openapiInfo,
@@ -69,7 +72,7 @@ export default async function maxserver(config = {}) {
69
72
  const port = this.maxserver.port ?? 3000;
70
73
  const host = this.maxserver.public ? '0.0.0.0' : '127.0.0.1';
71
74
  await this.listen({ port, host });
72
- console.log('Server running at ', getAddress(this));
75
+ console.log('🟢 ', getAddress(this));
73
76
  });
74
77
 
75
78
  await setupDevSounds(app);
package/src/setup.js CHANGED
@@ -21,16 +21,27 @@ export async function setupHelmet(app) {
21
21
  }
22
22
 
23
23
 
24
+
24
25
  export async function setupCors(app) {
25
26
  const isProd = app.maxserver.env === "production";
26
- const origin = app.maxserver.cors ?? "*";
27
- if (isProd && origin === "*") {
28
- app.log.warn("CORS: allowing all origins (*) in production");
29
- }
30
- await app.register(cors, { origin });
27
+ let origin = app.maxserver.cors ?? "*";
28
+
29
+ // Fix: Credentials + "*" = Browser Error
30
+ // If no origin is defined in dev, we should allow the specific requester
31
+ if (origin === "*" && !isProd)
32
+ origin = true; // Fastify-cors treats 'true' as "reflect the request origin"
33
+
34
+ if (isProd && (origin === "*" || origin === true))
35
+ app.log.warn("CORS: allowing all origins in production with credentials is risky");
36
+
37
+ await app.register(cors, {
38
+ origin,
39
+ credentials: true
40
+ });
31
41
  }
32
42
 
33
43
 
44
+
34
45
  export async function setupCookie(app) {
35
46
  await app.register(cookie, {
36
47
  secret: app.maxserver.secret,