UNPKG

@timshel_npm/maildev

Version:

SMTP Server with async API and Web Interface for viewing and testing emails during development

27 lines (26 loc) 780 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.auth = auth; /** * MailDev - auth.js */ function auth(user, password) { return function (req, res, next) { // allow health checks without auth if (req.path === "/healthz") { return next(); } let auth; if (req.headers.authorization) { auth = Buffer.from(req.headers.authorization.substring(6), "base64").toString().split(":"); } if (!auth || auth[0] !== user || auth[1] !== password) { res.statusCode = 401; res.setHeader("WWW-Authenticate", 'Basic realm="Authentication required"'); res.send("Unauthorized"); } else { next(); } }; }