Skip to content

Instantly share code, notes, and snippets.

@rgwozdz
Created May 30, 2018 20:19
Show Gist options
  • Save rgwozdz/0926c83f83f81f31f738d6aa9692abc8 to your computer and use it in GitHub Desktop.
Save rgwozdz/0926c83f83f81f31f738d6aa9692abc8 to your computer and use it in GitHub Desktop.
Koop-docs: output-services usage of authorize
/**
* Handler for service, layer, and query routes
* @param {object} req request object
* @param {object} res response object
*/
Geoservices.prototype.featureServer = function (req, res) {
// Is model configured for token-authorization?
if (typeof this.model.authorize === 'function') {
this.model.authorize(req.query.token)
.then(valid => {
// model will be available when this is instantiated with the Koop controller
pullDataAndRoute(this.model, req, res)
})
.catch(err => {
if (err.code === 401) FeatureServer.error.authorization(req, res)
else res.status(err.code || 500).json({error: err.message})
})
} else {
pullDataAndRoute(this.model, req, res)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment