feat(typedserver): add noCache option to disable client-side caching and set no-cache headers on responses
This commit is contained in:
@@ -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.'
|
||||
}
|
||||
|
||||
@@ -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', '*');
|
||||
|
||||
Reference in New Issue
Block a user