minimalistic-server 0.0.46 → 0.0.48

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 +1 -1
  2. package/index.mjs +12 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # node-minimalistic-server
2
2
  Minimalistic server library for Node.js. It supports routing, middlewares, parsing common request bodies (JSON, form data, etc), static file serving.
3
- In order to see how it works, you can download and run this [demo project](https://github.com/surenenfiajyan/files/raw/refs/heads/main/gallery.zip).
3
+ In order to see how it works, you can download and run this [demo project](https://github.com/surenenfiajyan/files/raw/refs/heads/main/gallery.zip) (in the project root directory run `npm install` and then `npm start`).
package/index.mjs CHANGED
@@ -2118,23 +2118,27 @@ function normalizeStaticFileDirectories(staticFileDirectoryOrDirectories) {
2118
2118
  }
2119
2119
 
2120
2120
  staticFileDirectoryOrDirectories = staticFileDirectoryOrDirectories.filter(x => x !== null && typeof x === 'object' || typeof x === 'string').map(x => {
2121
- let serverFilePath = '', urlPath = '', showWholeDirectory = false;;
2121
+ let serverFilePath = '', urlPath = '', showWholeDirectory = false, maxAgeInSeconds = -1;
2122
+ const defaultMaxAge = 5 * 24 * 60 * 60;
2122
2123
 
2123
2124
  if (typeof x === 'string') {
2124
2125
  serverFilePath = urlPath = x;
2125
2126
  showWholeDirectory = false;
2127
+ maxAgeInSeconds = defaultMaxAge;
2126
2128
  } else {
2127
- ({ serverFilePath, urlPath, showWholeDirectory } = x);
2129
+ ({ serverFilePath, urlPath, showWholeDirectory, maxAgeInSeconds } = x);
2128
2130
  }
2129
2131
 
2130
2132
  urlPath = `${urlPath}`.split('/').filter(x => x).join('/');
2131
2133
  serverFilePath = `${serverFilePath}`.split('/').filter(x => x).join('/');
2132
2134
  showWholeDirectory = !!showWholeDirectory;
2135
+ maxAgeInSeconds = Math.floor(+(maxAgeInSeconds ?? defaultMaxAge));
2133
2136
 
2134
2137
  return {
2135
2138
  urlPath,
2136
2139
  serverFilePath,
2137
2140
  showWholeDirectory,
2141
+ maxAgeInSeconds,
2138
2142
  };
2139
2143
  });
2140
2144
  } else {
@@ -2323,9 +2327,12 @@ async function handleRequest(req, routes, staticFileDirectories, handleNotFoundE
2323
2327
 
2324
2328
  if (!resp) {
2325
2329
  resp = new FileResponse(filePath);
2326
- resp.addCustomHeaders({
2327
- 'Cache-Control': 'public, max-age=432000',
2328
- });
2330
+
2331
+ if (staticFileOrDirectory.maxAgeInSeconds > 0) {
2332
+ resp.addCustomHeaders({
2333
+ 'Cache-Control': `public, max-age=${maxAgeInSeconds}`,
2334
+ });
2335
+ }
2329
2336
 
2330
2337
  if (handleNotFoundError) {
2331
2338
  resp.setNotFoundErrorCustomResponseHandler(() => handleNotFoundError(request));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimalistic-server",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "engines" : {
5
5
  "npm" : ">=8.6.0",
6
6
  "node" : ">=22.0.0"