zsyp 1.3.2 → 1.4.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.
Files changed (3) hide show
  1. package/index.js +5 -1
  2. package/lib/app.js +16 -2
  3. package/package.json +5 -6
package/index.js CHANGED
@@ -1,4 +1,8 @@
1
- require('dotenv').config({ path: '/etc/default/zsyp' });
1
+ try {
2
+ process.loadEnvFile('/etc/default/zsyp');
3
+ } catch {
4
+ console.error('Failed to load config file.');
5
+ }
2
6
 
3
7
  const makeApp = require('./lib/app');
4
8
 
package/lib/app.js CHANGED
@@ -1,6 +1,6 @@
1
+ const { json } = require('node:stream/consumers');
1
2
  const connect = require('@pirxpilot/connect');
2
3
  const mniam = require('mniam');
3
- const { json } = require('body-parser');
4
4
  const router = require('./router');
5
5
  const event = require('./event');
6
6
 
@@ -14,9 +14,23 @@ function makeApp(opts = {}) {
14
14
  opts.db = mniam.db(database);
15
15
  app.db = opts.db;
16
16
 
17
- app.use(json({ limit: 5000, type: ['*/json', 'application/csp-report'] }));
17
+ app.use(bodyParser());
18
+
18
19
  app.use('/csp', router({ ...opts, name: 'csp', domains }));
19
20
  app.use('/event', router({ ...opts, converter: event.converter }));
20
21
 
21
22
  return app;
22
23
  }
24
+
25
+ function bodyParser() {
26
+ return async (req, _res, next) => {
27
+ if (req.method !== 'POST') {
28
+ return next();
29
+ }
30
+ const contentType = req.headers['content-type'];
31
+ if (contentType?.endsWith('json') || contentType === 'application/csp-report') {
32
+ req.body = await json(req);
33
+ }
34
+ next();
35
+ };
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zsyp",
3
- "version": "1.3.2",
3
+ "version": "1.4.1",
4
4
  "description": "CSP violation reports logger.",
5
5
  "author": {
6
6
  "name": "Damian Krzeminski",
@@ -16,18 +16,17 @@
16
16
  "logger"
17
17
  ],
18
18
  "dependencies": {
19
- "@pirxpilot/connect": "^4.0.0",
20
- "body-parser": "~1",
21
- "debug": "~2 || ~3 || ~4",
22
- "dotenv": "~16",
19
+ "@pirxpilot/connect": "~4",
20
+ "debug": "~4",
23
21
  "error-stack-parser": "^2.1.4",
24
22
  "lru-cache": "~11",
25
23
  "mniam": "~4",
24
+ "mongodb": "~6",
26
25
  "source-map": "^0.7.4",
27
26
  "useragent": "^2.3.0"
28
27
  },
29
28
  "devDependencies": {
30
- "@biomejs/biome": "^1.9.4",
29
+ "@biomejs/biome": "2.0.6",
31
30
  "supertest-fetch": "~2"
32
31
  },
33
32
  "scripts": {