47 lines
742 B
JavaScript
Raw Normal View History

2015-11-04 17:31:07 +01:00
'use strict';
/**
* Module dependencies
*/
// Public node modules.
const _ = require('lodash');
const Grant = require('grant-koa');
/**
* Grant hook
*/
module.exports = function (strapi) {
const hook = {
/**
* Default options
*/
defaults: {
grant: {}
},
/**
* Initialize the hook
*/
initialize: function (cb) {
2015-11-19 22:54:54 +01:00
_.defaultsDeep(strapi.api.user.config.grant, {
2015-11-04 17:31:07 +01:00
server: {
protocol: strapi.config.ssl ? 'https' : 'http',
host: strapi.config.host + ':' + strapi.config.port
}
2015-11-04 17:59:43 +01:00
});
2015-11-19 22:54:54 +01:00
const grant = new Grant(strapi.api.user.config.grant);
2015-11-04 17:59:43 +01:00
2015-11-04 17:31:07 +01:00
strapi.app.use(strapi.middlewares.mount(grant));
cb();
}
};
return hook;
};