Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
OGC
node-3DPSx
Commits
c3e3375a
Commit
c3e3375a
authored
Jul 14, 2020
by
Athanasios
Browse files
redirect requests
parent
5500bf49
Changes
4
Hide whitespace changes
Inline
Side-by-side
routes/v1.js
View file @
c3e3375a
...
...
@@ -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
src/customSanitizers.js
View file @
c3e3375a
const
toLower
=
(
value
)
=>
{
if
(
!
value
)
return
;
return
value
.
toLowerCase
();
}
...
...
src/getCapabilitiesHandler.js
View file @
c3e3375a
...
...
@@ -9,7 +9,7 @@ const getCapabilitiesHandler = (req, res) => {
let
capabilities
=
compiledFunction
({
layers
:
layers
});
res
.
set
(
"
Content-Type
"
,
"
application/xml
"
);
res
.
status
(
200
).
send
(
capabilities
);
});
}
...
...
src/redirectTo.js
0 → 100644
View file @
c3e3375a
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment