"use strict"; const isURL = require("@validatem/is-url"); const wrapError = require("@validatem/wrap-error"); const ignoreResult = require("@validatem/ignore-result"); const ValidationError = require("@validatem/error"); module.exports = function (options = {}) { let allowedProtocols = (options.permitInsecure === true) ? [ "http://", "https://" ] : [ "https://" ]; return wrapError("modular-matrix.is-homeserver-url", "Must be a valid Matrix homeserver URL", ignoreResult([ isURL(allowedProtocols), function isHomeserverURL(value) { if (value.pathname != null && value.pathname !== "/") { throw new ValidationError(`Must not include a path`, { code: "modular-matrix.is-homeserver-url.path" }); } else if (value.query != null) { throw new ValidationError(`Must not include query parameters`, { code: "modular-matrix.is-homeserver-url.query" }); } } ]), { preserveOriginalErrors: true }); };