From b9f14866a8d30601ee8e6a06163a3ea6f89cf00a Mon Sep 17 00:00:00 2001 From: loicsaintroch Date: Wed, 2 Dec 2015 16:52:52 +0100 Subject: [PATCH] Fix Strapi prototype --- lib/Strapi.js | 11 +++++++++++ lib/server.js | 11 +++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Strapi.js b/lib/Strapi.js index ffef8233d9..339f5a63d8 100755 --- a/lib/Strapi.js +++ b/lib/Strapi.js @@ -36,6 +36,17 @@ function Strapi() { // Mixin support for `Strapi.prototype.after()`. mixinAfter(this); + // Bind `this` context for all `Strapi.prototype.*` methods. + 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); + this.isLocalStrapiValid = this.isLocalStrapiValid.bind(this); + this.isStrapiAppSync = this.isStrapiAppSync.bind(this); + // Expose `koa`. this.server = require('koa'); this.app = require('koa')(); diff --git a/lib/server.js b/lib/server.js index 258136d2be..fe3c7dc8bb 100755 --- a/lib/server.js +++ b/lib/server.js @@ -12,6 +12,13 @@ const Strapi = require('./Strapi'); * (maintains backwards compatibility with constructor usage). */ -module.exports = function () { +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);