Simplify server start

This commit is contained in:
Aurélien Georget 2016-07-07 17:03:48 +02:00
parent a29fac28e3
commit 086e05c31f
4 changed files with 10 additions and 37 deletions

View File

@ -14,7 +14,7 @@ const cluster = require('cluster');
const _ = require('lodash');
// Local Strapi dependencies.
const server = require('../lib/server');
const strapi = require('../lib/');
// Logger.
const logger = require('strapi-utils').logger;
@ -28,9 +28,6 @@ const logger = require('strapi-utils').logger;
module.exports = function () {
// Now load up the Strapi framework for real.
const strapi = server();
// Only log if the process is a master.
if (cluster.isMaster) {
strapi.log.info('Starting the application in interactive mode...');

View File

@ -10,7 +10,7 @@
const path = require('path');
// Local Strapi dependencies.
const strapi = require('../lib/server');
const isLocalStrapiValid = require('../lib/private/isLocalStrapiValid');
const packageJSON = require('../package.json');
// Logger.
@ -34,14 +34,14 @@ module.exports = function () {
// Use the app's local `strapi` in `node_modules` if it's existant and valid.
const localStrapiPath = path.resolve(scope.rootPath, 'node_modules', 'strapi');
if (strapi.isLocalStrapiValid(localStrapiPath, scope.rootPath)) {
if (isLocalStrapiValid(localStrapiPath, scope.rootPath)) {
return require(localStrapiPath).start(scope, afterwards);
}
// Otherwise, if no workable local `strapi` module exists,
// run the application using the currently running version
// of `strapi`. This is probably always the global install.
strapi().start(scope, afterwards);
return require('../lib/')().start(scope, afterwards);
function afterwards(err, strapi) {
if (err) {

View File

@ -1,24 +1,27 @@
'use strict';
// Start date
global.startedAt = Date.now();
/**
* Module dependencies
*/
// Local dependencies.
const Server = require('./server');
const strapi = require('./Strapi');
/**
* Instantiate and expose a Strapi singleton
* (maintains legacy support).
*/
module.exports = new Server(); // Strapi instance instanciated
module.exports = new strapi(); // Strapi instance instanciated
/**
* Expose constructor for convenience/tests
*/
module.exports.Strapi = Server; // Strapi instance not instanciated
module.exports.Strapi = strapi; // Strapi instance not instanciated
// To access the Strapi application constructor, do:
// var strapi = require('strapi').constructor;

View File

@ -1,27 +0,0 @@
'use strict';
// Start date
global.startedAt = Date.now();
/**
* Module dependencies
*/
// Local dependencies.
const strapi = require('./Strapi');
/**
* Expose `Strapi` factory
* (maintains backwards compatibility with constructor usage).
*/
module.exports = strapiFactory;
function strapiFactory() {
return new strapi();
}
// Backwards compatibility for Strapi singleton usage.
const singleton = strapiFactory();
strapiFactory.isLocalStrapiValid = singleton.isLocalStrapiValid.bind(singleton);
strapiFactory.isStrapiAppSync = singleton.isStrapiAppSync.bind(singleton);