fix(server): Fix response content manipulation for HTML files with injectReload
This commit is contained in:
		| @@ -1,5 +1,11 @@ | ||||
| # Changelog | ||||
|  | ||||
| ## 2025-01-28 - 3.0.55 - fix(server) | ||||
| Fix response content manipulation for HTML files with injectReload | ||||
|  | ||||
| - Moved fileString declaration inside HTML file handling block to prevent unnecessary string conversion for non-HTML files. | ||||
| - Corrected responseContent assignment to ensure modified HTML strings are converted back to Buffer format. | ||||
|  | ||||
| ## 2025-01-28 - 3.0.54 - fix(servertools) | ||||
| Fixed an issue with compression results handling in HandlerStatic where content was always being written even if not compressed. | ||||
|  | ||||
|   | ||||
| @@ -3,6 +3,6 @@ | ||||
|  */ | ||||
| export const commitinfo = { | ||||
|   name: '@api.global/typedserver', | ||||
|   version: '3.0.54', | ||||
|   version: '3.0.55', | ||||
|   description: 'A TypeScript-based project for easy serving of static files with support for live reloading, compression, and typed requests.' | ||||
| } | ||||
|   | ||||
| @@ -135,8 +135,8 @@ export class TypedServer { | ||||
|         '/*', | ||||
|         new servertools.HandlerStatic(this.options.serveDir, { | ||||
|           responseModifier: async (responseArg) => { | ||||
|             let fileString = responseArg.responseContent.toString(); | ||||
|             if (plugins.path.parse(responseArg.path).ext === '.html') { | ||||
|               let fileString = responseArg.responseContent.toString(); | ||||
|               const fileStringArray = fileString.split('<head>'); | ||||
|               if (this.options.injectReload && fileStringArray.length === 2) { | ||||
|                 fileStringArray[0] = `${fileStringArray[0]}<head> | ||||
| @@ -152,6 +152,7 @@ export class TypedServer { | ||||
|                 `; | ||||
|                 fileString = fileStringArray.join(''); | ||||
|                 console.log('injected typedserver script.'); | ||||
|                 responseArg.responseContent = Buffer.from(fileString); | ||||
|               } else if (this.options.injectReload) { | ||||
|                 console.log('Could not insert typedserver script'); | ||||
|               } | ||||
| @@ -164,7 +165,7 @@ export class TypedServer { | ||||
|             return { | ||||
|               headers, | ||||
|               path: responseArg.path, | ||||
|               responseContent: Buffer.from(fileString), | ||||
|               responseContent: responseArg.responseContent, | ||||
|             }; | ||||
|           }, | ||||
|           serveIndexHtmlDefault: true, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user