{"library":"lws-range","title":"lws-range: HTTP Range Request Middleware for lws","description":"This package, `lws-range`, is a middleware plugin designed for the `local-web-server` (`lws`) ecosystem, specifically adding robust support for HTTP Range Requests. It effectively wraps the `koa-range` library to integrate this functionality seamlessly into `lws` servers. As of version 4.0.1, it provides compliant handling of partial content requests, enabling clients to request specific byte ranges of a resource, which is crucial for features like video streaming, large file downloads with resume capabilities, and efficient caching. The project appears to be actively maintained, indicated by recent version releases and continuous integration. Its primary differentiator is its deep integration with the `lws` server, providing a simple `--stack` activation for this common HTTP feature without needing to manually configure low-level range request parsing. It mandates Node.js version 12.17 or higher.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install lws-range"],"cli":null},"imports":["import lwsRange from 'lws-range';","const lwsRange = require('lws-range');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import lws from 'lws';\nimport lwsRange from 'lws-range';\nimport lwsStatic from 'lws-static'; // Assuming lws-static is also installed\nimport { resolve } from 'path';\nimport { writeFileSync, mkdirSync } from 'fs';\n\nconst publicDir = resolve(__dirname, './public');\nmkdirSync(publicDir, { recursive: true });\n\n// Create a sample large file for testing range requests\nconst largeFilePath = resolve(publicDir, 'large-file.txt');\nconst dummyContent = 'This is a sample text file to demonstrate HTTP Range requests. '.\n  repeat(100) + 'It should be sufficiently long to make range requests meaningful.';\nwriteFileSync(largeFilePath, dummyContent);\n\n// Create a simple lws server with range request support and static file serving\nconst server = lws.create({\n  // The middleware stack defines the order of processing\n  stack: [\n    // lws-range must come before lws-static to handle range requests for static files\n    lwsRange(), \n    lwsStatic({ \n      root: publicDir, // Serve files from the 'public' directory\n      index: ['index.html', 'index.htm'] // Specify default index files\n    })\n  ],\n  port: process.env.PORT ?? 8000 // Listen on port 8000 or specified by env var\n});\n\nserver.listen(server.port, () => {\n  console.log(`lws server with range support listening on http://localhost:${server.port}`);\n  console.log('To test, create a file named ' + largeFilePath + ' (or use the one created by this script).');\n  console.log('Then try sending a curl request with a Range header, e.g.,');\n  console.log(`curl -I -H \"Range: bytes=0-100\" http://localhost:${server.port}/large-file.txt`);\n  console.log(`curl -H \"Range: bytes=0-10\" http://localhost:${server.port}/large-file.txt`);\n});","lang":"typescript","description":"Sets up an `lws` server programmatically with `lws-range` and `lws-static` middleware, demonstrating how to enable HTTP Range Request support for static files. Includes setup for a test file.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}