@lopatnov/express-reverse-proxy 5.0.7 → 5.0.9

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/README.md +4 -4
  2. package/package.json +1 -1
  3. package/server.js +15 -2
package/README.md CHANGED
@@ -360,10 +360,10 @@ Controls HTTP request logging (Morgan). Enabled by default (`dev` format). Set t
360
360
  }
361
361
  ```
362
362
 
363
- | Option | Default | Description |
364
- | -------- | ------------ | -------------------------------------------------------------- |
365
- | `format` | `"combined"` | Morgan format: `combined`, `common`, `dev`, `short`, or `tiny` |
366
- | `file` | none | Path to log file (relative to config file). Appended if exists |
363
+ | Option | Default | Description |
364
+ | -------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
365
+ | `format` | `"dev"` (console) / `"combined"` (file) | Morgan format: `combined`, `common`, `dev`, `short`, or `tiny`. Defaults to `"combined"` when `file` is set, `"dev"` otherwise |
366
+ | `file` | none | Path to log file (relative to config file). Appended if exists |
367
367
 
368
368
  When `file` is set, logs are written to the file only (not to the console).
369
369
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lopatnov/express-reverse-proxy",
3
3
  "email": "oleksandr@lopatnov.cv.ua",
4
- "version": "5.0.7",
4
+ "version": "5.0.9",
5
5
  "description": "Node.js CLI tool to serve static front-end files with a reverse proxy for back-end APIs",
6
6
  "type": "module",
7
7
  "author": "lopatnov",
package/server.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn, spawnSync } from 'node:child_process';
3
+ import { randomInt } from 'node:crypto';
3
4
  import fs from 'node:fs';
4
5
  import https from 'node:https';
5
6
  import path from 'node:path';
@@ -543,7 +544,7 @@ function setupUpload(router, siteConfig, configDir) {
543
544
  const ext = path.extname(file.originalname);
544
545
  const base =
545
546
  path.basename(file.originalname, ext).replaceAll(/[^a-zA-Z0-9_.-]/g, '_') || 'file';
546
- cb(null, `${base}-${Date.now()}-${Math.round(Math.random() * 1e9)}${ext}`);
547
+ cb(null, `${base}-${Date.now()}-${randomInt(0, 1_000_000_000)}${ext}`);
547
548
  },
548
549
  });
549
550
 
@@ -556,7 +557,19 @@ function setupUpload(router, siteConfig, configDir) {
556
557
  ? uploader.array(uploadConfig.fieldName)
557
558
  : uploader.any();
558
559
 
559
- router.post(uploadUrlPath, multerMiddleware, handleUploadResponse);
560
+ router.post(uploadUrlPath, (req, res, next) => {
561
+ multerMiddleware(req, res, (err) => {
562
+ if (err instanceof multer.MulterError) {
563
+ const status = err.code === 'LIMIT_FILE_SIZE' ? 413 : 400;
564
+ return res.status(status).json({ error: err.message });
565
+ }
566
+ if (err?.status || err?.statusCode) {
567
+ return res.status(err.statusCode || err.status).json({ error: err.message });
568
+ }
569
+ if (err) return next(err);
570
+ return handleUploadResponse(req, res);
571
+ });
572
+ });
560
573
  router.use(uploadUrlPath, express.static(uploadDir));
561
574
  console.log(`[upload] POST ${uploadUrlPath} → ${uploadDir}`);
562
575
  }