Compare commits

...

4 Commits

7 changed files with 28 additions and 14 deletions

View File

@ -1,5 +1,17 @@
# Changelog
## 2025-03-16 - 3.0.69 - fix(servertools)
Fix compression stream creation returns, handler proxy buffer conversion, and sitemap URL concatenation
- Return compression stream immediately in createCompressionStream for each case instead of using break statements
- Convert proxied response to a Buffer in handler proxy rather than throwing an error when it isn't a string
- Fix addUrls method in sitemap to correctly concatenate new URLs without duplicating existing entries
## 2025-02-07 - 3.0.68 - fix(cache-manager)
Simplify cache control headers in cache manager
- Removed unnecessary cache control headers while setting modern Cache-Control.
## 2025-02-06 - 3.0.67 - fix(serviceworker)
Enhance header security for cached resources in service worker

View File

@ -1,6 +1,6 @@
{
"name": "@api.global/typedserver",
"version": "3.0.67",
"version": "3.0.69",
"description": "A TypeScript-based project for easy serving of static files with support for live reloading, compression, and typed requests.",
"type": "module",
"exports": {

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@api.global/typedserver',
version: '3.0.67',
version: '3.0.69',
description: 'A TypeScript-based project for easy serving of static files with support for live reloading, compression, and typed requests.'
}

View File

@ -111,6 +111,7 @@ export class Compressor {
switch (method) {
case 'gzip':
compressionStream = plugins.zlib.createGzip();
return compressionStream;
case 'br':
compressionStream = plugins.zlib.createBrotliCompress({
chunkSize: 16 * 1024,
@ -118,10 +119,13 @@ export class Compressor {
},
});
return compressionStream;
case 'deflate':
compressionStream = plugins.zlib.createDeflate();
return compressionStream;
default:
compressionStream = plugins.smartstream.createPassThrough();
return compressionStream;
}
}
}
}

View File

@ -41,10 +41,11 @@ export class HandlerProxy extends Handler {
}
let responseToSend: Buffer = proxiedResponse.body;
if (typeof responseToSend !== 'string') {
console.log(proxyRequestUrl);
console.log(responseToSend);
throw new Error(`Proxied response is not a string, but ${typeof responseToSend}`);
// Remove incorrect type check that expects responseToSend to be a string
// Instead, ensure it's a Buffer for consistent handling
if (!Buffer.isBuffer(responseToSend)) {
responseToSend = Buffer.from(responseToSend.toString());
}
if (optionsArg && optionsArg.responseModifier) {
@ -74,4 +75,4 @@ export class HandlerProxy extends Handler {
res.end();
});
}
}
}

View File

@ -63,6 +63,6 @@ export class Sitemap {
* adds urls to the current set of urls
*/
public addUrls(urlsArg: IUrlInfo[]) {
this.urls = this.urls.concat(this.urls, urlsArg);
this.urls = this.urls.concat(urlsArg);
}
}
}

View File

@ -184,11 +184,8 @@ export class CacheManager {
headers.set('Cross-Origin-Resource-Policy', 'cross-origin');
}
// Prevent browser caching while allowing ServiceWorker caching.
// Set caching headers - use modern Cache-Control only
headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
headers.set('Pragma', 'no-cache');
headers.set('Expires', '0');
headers.set('Surrogate-Control', 'no-store');
// IMPORTANT: Read the full response body as a blob to avoid issues (e.g., Safari locked streams).
const bodyBlob = await responseToPutToCache.blob();