Add source code link, basic input validation, and monospace error display

master
Sven Slootweg 5 years ago
parent 4104c8778b
commit 6c43050a8c

@ -9,6 +9,7 @@ const url = require("url");
const autodiscoverClientConfiguration = require("@modular-matrix/autodiscover-client-configuration"); const autodiscoverClientConfiguration = require("@modular-matrix/autodiscover-client-configuration");
const bhttp = require("bhttp"); const bhttp = require("bhttp");
const createError = require("create-error"); const createError = require("create-error");
const { ValidationError, validateValue, required, isString } = require("validatem");
let UpstreamError = createError("UpstreamError"); let UpstreamError = createError("UpstreamError");
@ -34,6 +35,17 @@ router.get("/", (req, res) => {
}); });
router.get("/show-rooms", (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 Promise.try(() => {
return autodiscoverClientConfiguration.discover(req.query.hostname); return autodiscoverClientConfiguration.discover(req.query.hostname);
}).then((clientConfiguration) => { }).then((clientConfiguration) => {
@ -68,7 +80,7 @@ router.get("/show-rooms", (req, res) => {
app.use(router); app.use(router);
app.use((error, req, res, next) => { 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 }); res.render("error", { error: error });
} else { } else {
throw error; throw error;

@ -15,7 +15,8 @@
"express": "^4.17.1", "express": "^4.17.1",
"express-promise-router": "^3.0.3", "express-promise-router": "^3.0.3",
"react": "^16.9.0", "react": "^16.9.0",
"react-dom": "^16.9.0" "react-dom": "^16.9.0",
"validatem": "^0.2.0"
}, },
"devDependencies": { "devDependencies": {
"nodemon": "^1.19.1" "nodemon": "^1.19.1"

@ -2,6 +2,11 @@ body {
font-family: sans-serif; font-family: sans-serif;
} }
h1 {
display: inline-block;
margin-right: 2em;
}
.container { .container {
max-width: 960px; max-width: 960px;
margin: 0 auto; margin: 0 auto;

@ -7,7 +7,9 @@ const Layout = require("./layout");
module.exports = function Error({ error }) { module.exports = function Error({ error }) {
return ( return (
<Layout> <Layout>
{error.message} <pre>
{error.message}
</pre>
</Layout> </Layout>
); );
}; };

@ -15,6 +15,7 @@ module.exports = function Layout({ children }) {
<body> <body>
<div className="container"> <div className="container">
<h1>Matrix Room List Viewer</h1> <h1>Matrix Room List Viewer</h1>
<a href="https://git.cryto.net/joepie91/matrix-room-list-viewer">Source code</a>
<hr/> <hr/>
{children} {children}
</div> </div>

Loading…
Cancel
Save