|
1 月之前 | |
---|---|---|
.. | ||
src | 1 月之前 | |
LICENSE | 1 月之前 | |
README.md | 1 月之前 | |
package.json | 1 月之前 |
Connect integration with http-auth module.
Via git (or downloaded tarball):
$ git clone git://github.com/http-auth/http-auth-connect.git
Via npm:
$ npm install http-auth-connect
// Express module.
// eslint-disable-next-line node/no-unpublished-require
const express = require("express");
// Authentication module.
// eslint-disable-next-line node/no-unpublished-require
const auth = require("http-auth");
// eslint-disable-next-line node/no-unpublished-require
const authConnect = require("http-auth-connect");
const basic = auth.basic({
realm: "Simon Area.",
file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass
});
// Application setup.
const app = express();
app.use(authConnect(basic));
// Setup route.
app.get("/", (req, res) => {
res.send(`Hello from express - ${req.user}!`);
});
// Start server.
app.listen(1337, () => {
// Log URL.
console.log("Server running at http://127.0.0.1:1337/");
});
It uses mocha, so just run following command in package directory:
$ npm test
The MIT License (MIT)