lws-basic-auth is a middleware plugin designed to password-protect local-web-server (lws) instances using HTTP Basic Authentication. It integrates directly into the `lws` command-line and programmatic configuration, allowing users to define a username and password to restrict access to the served content. The current stable version is 2.0.0. While `lws` itself has seen infrequent updates, this middleware provides a focused and lightweight solution specifically for the `lws` ecosystem. It differentiates itself from general-purpose basic authentication libraries by being tightly coupled with `lws`'s plugin architecture, offering a streamlined setup for securing local development servers. Its release cadence is infrequent, suggesting it is a stable package in maintenance mode, receiving minimal updates.
npm install lws-basic-authVerified import paths — ran on the pinned version, not inferred.
This quickstart sets up an `lws` server with `lws-basic-auth` middleware, protecting a static HTML file. It demonstrates both programmatic setup with environment variables for credentials and accessing the protected resource.
Thoroughly test existing integrations when upgrading from 1.x to 2.x. Consult the main `lws` project's changelog and relevant middleware documentation for any related breaking changes or updated configuration patterns.
Deploy your `lws` server with HTTPS enabled when using `lws-basic-auth` in any environment beyond local development. Consider more robust authentication mechanisms for production applications handling sensitive data.
Use strong, unique credentials. Implement rate limiting or IP blocking at a higher level (e.g., reverse proxy, firewall) to mitigate brute-force attempts if `lws` is exposed directly to the internet.
Ensure `lws-basic-auth` is listed before any middleware that serves static files or routes that need protection in your `lws` `stack` configuration.
Install `lws` globally or as a project dependency: `npm install lws` or `npm install --save-dev lws`.
Ensure the client is configured to send the correct `Authorization: Basic <base64-encoded-credentials>` header. For browsers, a prompt should appear; ensure correct credentials are entered. For `curl`, use `curl -u username:password http://localhost:8000`.
Provide both `--auth.user <username>` and `--auth.pass <password>` via the command line, or `auth: { user: '...', pass: '...' }` in your programmatic `lws` configuration object.