|
|
|
@ -9,6 +9,7 @@ const url = require("url");
|
|
|
|
|
const autodiscoverClientConfiguration = require("@modular-matrix/autodiscover-client-configuration");
|
|
|
|
|
const bhttp = require("bhttp");
|
|
|
|
|
const createError = require("create-error");
|
|
|
|
|
const { ValidationError, validateValue, required, isString } = require("validatem");
|
|
|
|
|
|
|
|
|
|
let UpstreamError = createError("UpstreamError");
|
|
|
|
|
|
|
|
|
@ -34,6 +35,17 @@ router.get("/", (req, res) => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get("/show-rooms", (req, res) => {
|
|
|
|
|
validateValue(req.query, {
|
|
|
|
|
hostname: [ required, isString, (string) => {
|
|
|
|
|
console.log(string.length);
|
|
|
|
|
|
|
|
|
|
if (string.length === 0) {
|
|
|
|
|
throw new ValidationError("May not be empty");
|
|
|
|
|
}
|
|
|
|
|
} ],
|
|
|
|
|
since: [ isString ]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Promise.try(() => {
|
|
|
|
|
return autodiscoverClientConfiguration.discover(req.query.hostname);
|
|
|
|
|
}).then((clientConfiguration) => {
|
|
|
|
@ -68,7 +80,7 @@ router.get("/show-rooms", (req, res) => {
|
|
|
|
|
app.use(router);
|
|
|
|
|
|
|
|
|
|
app.use((error, req, res, next) => {
|
|
|
|
|
if (error instanceof UpstreamError || error instanceof autodiscoverClientConfiguration.LookupFailed) {
|
|
|
|
|
if (error instanceof UpstreamError || error instanceof autodiscoverClientConfiguration.LookupFailed || error instanceof ValidationError) {
|
|
|
|
|
res.render("error", { error: error });
|
|
|
|
|
} else {
|
|
|
|
|
throw error;
|
|
|
|
|