{"library":"lws-blacklist","title":"lws-blacklist Middleware","description":"lws-blacklist is a middleware package for the `lws` (local-web-server) ecosystem, designed to forbid specific routes based on regular expressions. It integrates with `lws` to add a `--blacklist` CLI option or can be configured programmatically. The package is currently at version `3.0.0`, published approximately six years ago, and is part of the `lwsjs` suite of modular `lws` plugins. While `lws` itself uses Koa as its middleware engine, `lws-blacklist` provides a simplified interface for defining forbidden paths, making it a specialized solution for access control within an `lws` server setup. Its primary differentiator is its tight integration and configuration synergy with `lws`.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install lws-blacklist"],"cli":{"name":"lws","version":null}},"imports":["import Lws from 'lws';","import blacklistMiddleware from 'lws-blacklist';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Lws from 'lws';\nimport blacklistMiddleware from 'lws-blacklist';\n\nconst server = new Lws();\n\nasync function startServer() {\n  try {\n    const options = {\n      port: 8000,\n      stack: ['lws-static'], // Ensure static serving is also enabled\n      directory: './public', // Serve files from a 'public' directory\n      blacklist: ['/admin/(.*)', '/secret-page.html'], // Routes to forbid\n      // For programmatic use, the middleware itself is added to the stack\n      // but the configuration comes via options that lws-blacklist processes.\n      // If lws-blacklist exported a direct Koa middleware, it would look like:\n      // middleware: [blacklistMiddleware({ blacklist: ['/admin/(.*)'] })]\n    };\n\n    await server.start(options);\n    console.log(`lws-blacklist example server running at http://localhost:${options.port}`);\n    console.log('Try accessing http://localhost:8000/secret-page.html or http://localhost:8000/admin/dashboard.html');\n    console.log('Serving static files from ./public');\n  } catch (error) {\n    console.error('Failed to start lws server:', error);\n  }\n}\n\n// Create a public directory and some test files\nimport fs from 'fs';\nif (!fs.existsSync('./public')) fs.mkdirSync('./public');\nfs.writeFileSync('./public/index.html', '<h1>Hello from lws!</h1><p>Public page.</p>');\nfs.writeFileSync('./public/secret-page.html', '<h1>ACCESS DENIED</h1><p>This page should be blocked.</p>');\nfs.writeFileSync('./public/admin/dashboard.html', '<h1>Admin Dashboard</h1><p>This page should be blocked.</p>');\n\nstartServer();","lang":"javascript","description":"Demonstrates programmatic setup of an lws server with lws-blacklist, blocking specific URL patterns like '/admin/(.*)' and '/secret-page.html' using the `--blacklist` option equivalent.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}