Merge branch 'v2' of github.com:wistityhq/strapi into feature/json

This commit is contained in:
Aurélien Georget 2016-03-09 17:37:27 +01:00
commit f72e033b11
6 changed files with 13 additions and 162 deletions

View File

@ -40,7 +40,6 @@ function Strapi() {
this.load = this.load.bind(this);
this.start = this.start.bind(this);
this.stop = this.stop.bind(this);
this.restart = this.restart.bind(this);
this.initialize = this.initialize.bind(this);
this.exposeGlobals = this.exposeGlobals.bind(this);
this.runBootstrap = this.runBootstrap.bind(this);
@ -80,7 +79,6 @@ util.inherits(Strapi, events.EventEmitter);
Strapi.prototype.start = require('./start');
Strapi.prototype.stop = require('./stop');
Strapi.prototype.restart = require('./restart');
Strapi.prototype.server = require('koa');
Strapi.prototype.app = require('koa')();

View File

@ -20,7 +20,12 @@ module.exports = function (strapi) {
*/
defaults: {
grant: {}
authentication: {
server: {
protocol: strapi.config.ssl ? 'https' : 'http',
host: strapi.config.host + ':' + strapi.config.port
}
}
},
/**
@ -28,14 +33,8 @@ module.exports = function (strapi) {
*/
initialize: function (cb) {
if (_.isPlainObject(strapi.api.user)) {
_.defaultsDeep(strapi.api.user.config.grant, {
server: {
protocol: strapi.config.ssl ? 'https' : 'http',
host: strapi.config.host + ':' + strapi.config.port
}
});
const grant = new Grant(strapi.api.user.config.grant);
if (_.isPlainObject(strapi.config.authentication) && !_.isEmpty(strapi.config.authentication)) {
const grant = new Grant(strapi.config.authentication);
strapi.app.use(strapi.middlewares.mount(grant));
}

View File

@ -368,22 +368,6 @@ module.exports = function (strapi) {
});
},
/**
* Rebuild dictionary
*
* @param {Object} data
*
* @return {Function} cb
*/
rebuild: function (data, cb) {
process.nextTick(function () {
strapi.restart(function () {
cb(null, true);
});
});
},
/**
* Remove file or folder
*

View File

@ -3,35 +3,13 @@
/**
* `exposeGlobals()`
*
* Expose certain global variables
* (if config says so).
* Expose certain global variables.
*
* @api private
*/
module.exports = function exposeGlobals() {
const self = this;
// Globals explicitly disabled.
if (self.config.globals === false) {
return;
}
// Expose globals as an empty object.
self.config.globals = self.config.globals || {};
// Expose Async globally if enabled.
if (self.config.globals.async !== false) {
global.async = require('async');
}
// Expose Lodash globally if enabled.
if (self.config.globals._ !== false) {
global._ = require('lodash');
}
// Expose Strapi globally if enabled.
if (self.config.globals.strapi !== false) {
global.strapi = self;
}
global.async = require('async');
global._ = require('lodash');
global.strapi = this;
};

View File

@ -69,7 +69,7 @@ module.exports = function (strapi) {
// Get the hook defaults.
const defaults = (_.isFunction(hook.defaults) ? hook.defaults(strapi.config) : hook.defaults) || {};
_.defaults(strapi.config, defaults);
_.defaultsDeep(strapi.config, defaults);
}
// Load a hook and initialize it.

View File

@ -1,108 +0,0 @@
'use strict';
/**
* Module dependencies
*/
// Node.js core.
const cluster = require('cluster');
// Public node modules.
const _ = require('lodash');
const async = require('async');
/**
* Programmatically restart the server
* (useful for the Studio)
*/
module.exports = cb => {
console.log();
// Update the Strapi status (might be used
// by the core or some hooks).
strapi.reloading = true;
// Async module loader to rebuild a
// dictionary of the application.
async.auto({
// Rebuild the dictionaries.
dictionaries: cb => {
strapi.on('hook:_config:reloaded', () => {
strapi.on('hook:_api:reloaded', () => cb());
strapi.hooks._api.reload();
});
strapi.hooks._config.reload();
}
},
// Callback.
err => {
let count = 0;
// Just in case there is an error.
if (err) {
strapi.log.error('Impossible to reload the server');
strapi.log.error('Please restart the server manually');
strapi.stop();
}
// Tell the application the framework is reloading
// (might be used by some hooks).
strapi.reloading = true;
// Run adapters installation
if (cluster.isMaster) {
++count;
if (_.isPlainObject(strapi.config.views) && !_.isBoolean(strapi.config.views)) {
strapi.hooks.views.installation();
++count;
}
}
const installed = _.after(count, () => {
if (_.isPlainObject(strapi.config.reload) && !_.isEmpty(strapi.config.reload) && strapi.config.reload.workers > 0) {
strapi.log.warn('Application is restarting...');
console.log();
}
// Reload the router.
strapi.after('hook:router:reloaded', () => {
process.nextTick(() => cb());
// Update `strapi` status.
strapi.reloaded = true;
strapi.reloading = false;
// Finally inform the developer everything seems ok.
if (cluster.isMaster && _.isPlainObject(strapi.config.reload) && !_.isEmpty(strapi.config.reload) && strapi.config.reload.workers < 1) {
strapi.log.info('Application\'s dictionnary updated');
strapi.log.warn('You still need to restart your server to fully enjoy changes...');
}
strapi.once('restart:done', function () {
strapi.log.info('Application successfully restarted');
});
if (cluster.isMaster) {
_.forEach(cluster.workers, worker => worker.on('message', () => strapi.emit('restart:done')));
}
// Kill every worker processes.
_.forEach(cluster.workers, () => process.kill(process.pid, 'SIGHUP'));
});
// Reloading the router.
strapi.hooks.router.reload();
});
strapi.after('hook:views:installed', () => {
installed();
});
});
};