v3.4.0
New Features
- Dynamic Static File Serving and Directory Watching: Introduced dynamic serving of static files and automatic detection of changes in the static directory.
- Integrated Multipart/Form-Data Parsing: Added support for multipart/form-data using the
meroslibrary and renamedjsonHandlertobodyParser. - Support for Custom Maximum Request Size in
postMethod: Enhancedpostmethod to allow custom maximum request size. - Support for
{{@index}}in#eachDirective: Enabled use of{{@index}}placeholder within#eachblocks in the Simple Template Engine.
Details
- Dynamic Static File Serving: Now static files can be served dynamically without server restarts. The static directory is monitored for changes, ensuring that new files are immediately available.
- Multipart/Form-Data Parsing: The
meroslibrary is integrated to handle multipart/form-data, supporting file uploads and form fields. ThejsonHandlerfunction has been renamed tobodyParserfor clarity. - Custom Maximum Request Size: The
postmethod now supports an optional parameter for specifying a custom maximum request size, enhancing control over request handling. - Template Engine Enhancement: The
processEachfunction in the Simple Template Engine now supports the{{@index}}placeholder, allowing access to the current iteration index.
Changes
- Static File Handling: Implemented dynamic route registration, directory watching, improved path handling, and enhanced logging for static files.
- Multipart/Form-Data: Integrated
meroslibrary, updatedbodyParserfunction, improved error handling, and refactored code. postMethod: AddedcustomMaxRequestSizeparameter, updated TypeScript definition, and revised documentation.- Template Engine: Updated
processEachfunction to handle{{@index}}in nested#eachblocks and non-object items.
In-Depth Improvements
-
Static File Handling
- Dynamic Route Registration: Implemented a mechanism to dynamically register routes for static files, enabling the server to handle new files added to the static directory on-the-fly.
- Directory Watching: Added functionality to watch the static directory recursively for any changes (additions), ensuring new files are detected and served without restarting the server.
- Path Handling Refinement: Improved path handling to ensure that route paths are correctly constructed and include the static directory, regardless of the operating system (Windows, macOS, Linux).
- Enhanced Logging: Added detailed logging to trace the addition of new files, route registrations, and file serving, aiding in debugging and ensuring transparency of the process.
- startServer Method Update: Updated the
startServermethod to initialize theStaticAssetLoaderand serve static assets upon server start, integrating the new dynamic file serving feature seamlessly into the server lifecycle.
These changes ensure a more robust and flexible handling of static assets, improving the development and deployment workflow by removing the need for server restarts when static files are modified or added. The static directory is now monitored for changes, and newly added files are automatically registered and served. This ensures that any changes to the static assets are immediately reflected and accessible.
-
Multipart/Form-Data
- Integration with
meros: Added support for parsing multipart/form-data using themeroslibrary, which supports streaming and handles multiple parts efficiently. - Enhanced Request Handling: Updated the
bodyParserfunction to support multipart/form-data, in addition to JSON and URL-encoded form data. - Data Structure: Form fields and file uploads are now stored in the
req.bodyobject, with files accessible as arrays for each field name. - Improved Error Handling: Added logic to handle request size limits and unsupported media types more effectively.
- Refactored Code: Cleaned up and optimized the body parsing logic for better maintainability and performance.
- Function Renaming: Renamed
jsonHandlertobodyParserfor better clarity and consistency.
This new feature makes it easier to handle file uploads and complex form data in your LiteNode applications, enhancing the overall flexibility and functionality of the framework. The renaming of
jsonHandlertobodyParserclarifies the purpose of the function, making the codebase more intuitive. This enhancement allows for efficient parsing of file uploads and form fields, providing a more robust and flexible solution for handling multipart requests. - Integration with
-
postMethod- Enhanced
postMethod: Thepostmethod now accepts an optionalcustomMaxRequestSizeparameter as the last argument in the handler list. This parameter defines the maximum request size in megabytes. - Handler Adjustment: Modified internal handling to use the provided
customMaxRequestSizewhen present, or default to 1MB. - TypeScript Definition Update: The TypeScript definition (
litenode.d.ts) for thepostmethod has been updated to reflect the new parameter. It now allows for an array of route handlers and an optional number specifying the maximum request size. - Documentation Update: Updated examples in the documentation to demonstrate how to use the new
customMaxRequestSizeparameter.
This update enhances the flexibility and control over POST request handling, making it easier to manage and validate large payloads.
- Enhanced
-
Template Engine
- Enhancement: Updated the
processEachfunction to recognize and replace{{@index}}with the current iteration index. - Recursive Processing: Ensured that nested
#eachblocks correctly process the{{@index}}placeholder. - Non-Object Handling: Added support for
{{@index}}in non-object items by replacing the placeholder in the iteration content.
This new feature provides additional flexibility and control when working with arrays in templates, making it easier to create more dynamic and informative content by enhancing the
processEachfunction in the Simple Template Engine to support the{{@index}}placeholder within#eachblocks. The{{@index}}placeholder allows you to access the current index of the iteration, enabling more dynamic and flexible templates. - Enhancement: Updated the
This release significantly enhances flexibility and functionality across multiple aspects of the framework, from static file serving to request handling and template processing.