Commit c3e3375a authored by Athanasios's avatar Athanasios
Browse files

redirect requests

parent 5500bf49
......@@ -4,12 +4,54 @@ const { toLower } = require("../src/customSanitizers");
const { errorHandler } = require("../src/errorHandler");
const checkFactory = require("../src/validationCheckFactory");
const { getSceneHandler } = require("../src/getSceneHandler");
const { getCapabilitiesHandler } = require("../src/getCapabilitiesHandler");
const bb = require("../src/boundingbox");
const redirectTo = require("../src/redirectTo");
let router = express.Router();
const checks = [
...checkFactory.commonChecks(),
check("request")
.exists().withMessage("MissingParameterValue")
.customSanitizer(toLower)
.isIn(["getscene", "getcapabilities"]).withMessage("InvalidParameterValue")
];
router.route("/").get(checks, (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
let exception = errorHandler(errors);
res.set("Content-Type", "application/xml");
return res.status(400).send(exception);
}
redirectTo(req.query.request, req, res);
});
const capabilitiesChecks = [
check("request")
.exists().withMessage("MissingParameterValue")
.customSanitizer(toLower)
.equals("getcapabilities").withMessage("InvalidParameterValue")
];
router.route("/capabilities").get(capabilitiesChecks, (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
let exception = errorHandler(errors);
res.set("Content-Type", "application/xml");
return res.status(400).send(exception);
}
getCapabilitiesHandler(req, res);
});
const sceneChecks = [
check("request")
.exists().withMessage("MissingParameterValue")
.customSanitizer(toLower)
......@@ -39,18 +81,17 @@ const checks = [
.isIn(["true", "false"]).withMessage("InvalidParameterValue")
];
router.route("/")
.get(checks, (req, res) => {
router.route("/scene").get(sceneChecks, (req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
let exception = errorHandler(errors);
res.set("Content-Type", "application/xml");
return res.status(400).send(exception);
}
const errors = validationResult(req);
if (!errors.isEmpty()) {
let exception = errorHandler(errors);
res.set("Content-Type", "application/xml");
return res.status(400).send(exception);
}
getSceneHandler(req, res);
getSceneHandler(req, res);
});
});
module.exports = router;
\ No newline at end of file
const toLower = (value) => {
if(!value) return;
return value.toLowerCase();
}
......
......@@ -9,7 +9,7 @@ const getCapabilitiesHandler = (req, res) => {
let capabilities = compiledFunction({ layers: layers });
res.set("Content-Type", "application/xml");
res.status(200).send(capabilities);
});
}
......
const url = require('url');
const redirectTo = (request, req, res) => {
switch (request.toLowerCase()) {
case "getscene": {
res.redirect(
url.format({
pathname: `${req.baseUrl}/scene`,
query: req.query,
})
);
break;
}
case "getcapabilities": {
res.redirect(
url.format({
pathname: `${req.baseUrl}/capabilities`,
query: req.query,
})
);
break;
}
}
}
module.exports = redirectTo;
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment