Skip to content

v3.4.0

Compare
Choose a tag to compare
@LebCit LebCit released this 28 Jul 22:24
· 3 commits to main since this release

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 meros library and renamed jsonHandler to bodyParser.
  • Support for Custom Maximum Request Size in post Method: Enhanced post method to allow custom maximum request size.
  • Support for {{@index}} in #each Directive: Enabled use of {{@index}} placeholder within #each blocks 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 meros library is integrated to handle multipart/form-data, supporting file uploads and form fields. The jsonHandler function has been renamed to bodyParser for clarity.
  • Custom Maximum Request Size: The post method now supports an optional parameter for specifying a custom maximum request size, enhancing control over request handling.
  • Template Engine Enhancement: The processEach function 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 meros library, updated bodyParser function, improved error handling, and refactored code.
  • post Method: Added customMaxRequestSize parameter, updated TypeScript definition, and revised documentation.
  • Template Engine: Updated processEach function to handle {{@index}} in nested #each blocks and non-object items.

In-Depth Improvements

  1. 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 startServer method to initialize the StaticAssetLoader and 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.

  2. Multipart/Form-Data

    • Integration with meros: Added support for parsing multipart/form-data using the meros library, which supports streaming and handles multiple parts efficiently.
    • Enhanced Request Handling: Updated the bodyParser function 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.body object, 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 jsonHandler to bodyParser for 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 jsonHandler to bodyParser clarifies 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.

  3. post Method

    • Enhanced post Method: The post method now accepts an optional customMaxRequestSize parameter 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 customMaxRequestSize when present, or default to 1MB.
    • TypeScript Definition Update: The TypeScript definition (litenode.d.ts) for the post method 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 customMaxRequestSize parameter.

    This update enhances the flexibility and control over POST request handling, making it easier to manage and validate large payloads.

  4. Template Engine

    • Enhancement: Updated the processEach function to recognize and replace {{@index}} with the current iteration index.
    • Recursive Processing: Ensured that nested #each blocks 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 processEach function in the Simple Template Engine to support the {{@index}} placeholder within #each blocks. The {{@index}} placeholder allows you to access the current index of the iteration, enabling more dynamic and flexible templates.

This release significantly enhances flexibility and functionality across multiple aspects of the framework, from static file serving to request handling and template processing.