feat(typedserver): add noCache option to disable client-side caching and set no-cache headers on responses

This commit is contained in:
2026-01-23 22:42:04 +00:00
parent 4cc1efb7cc
commit c753206456
3 changed files with 22 additions and 2 deletions

View File

@@ -1,5 +1,12 @@
# Changelog
## 2026-01-23 - 8.3.0 - feat(typedserver)
add noCache option to disable client-side caching and set no-cache headers on responses
- Introduces an optional noCache?: boolean in the server options interface
- applyResponseHeaders now sets Cache-Control, Pragma, and Expires headers when noCache is true
- Existing CORS and security header behavior unchanged when noCache is not set or false
## 2026-01-23 - 8.2.0 - feat(typedserver)
serve bundled in-memory content with caching and reload injection

View File

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

View File

@@ -157,6 +157,12 @@ export interface IServerOptions {
* Set to true for defaults (brotli + gzip), false to disable, or provide detailed config
*/
compression?: plugins.smartserve.ICompressionConfig | boolean;
/**
* Disable all client-side caching by setting appropriate headers
* Useful for development or when content changes frequently
*/
noCache?: boolean;
}
export type THttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'ALL';
@@ -635,11 +641,18 @@ export class TypedServer {
}
/**
* Apply all configured headers (CORS, security) to a response
* Apply all configured headers (CORS, security, cache control) to a response
*/
private applyResponseHeaders(response: Response): Response {
const headers = new Headers(response.headers);
// No-cache headers
if (this.options.noCache) {
headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0');
headers.set('Pragma', 'no-cache');
headers.set('Expires', '0');
}
// CORS headers
if (this.options.cors) {
headers.set('Access-Control-Allow-Origin', '*');