maxserver 0.2.4 → 0.2.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/setup.js +16 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maxserver",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Node server setup based fastify",
5
5
  "author": "Max Matinpalo",
6
6
  "type": "module",
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,