Skip to content

Commit

Permalink
Merge pull request #7222 from strapi/chore/server-startup
Browse files Browse the repository at this point in the history
Fix server not accessible at bootstrap
  • Loading branch information
alexandrebodin committed Jul 28, 2020
2 parents da338f9 + cbc3e22 commit b5bfe60
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/strapi/lib/Strapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Strapi {
this.app = new Koa();
this.router = new Router();

this.server = http.createServer(this.handleRequest.bind(this));

// Logger.
this.log = logger;

Expand All @@ -68,6 +70,14 @@ class Strapi {
return ee({ dir: this.dir, logger });
}

handleRequest(req, res) {
if (!this.requestHandler) {
this.requestHandler = this.app.callback();
}

return this.requestHandler(req, res);
}

requireProjectBootstrap() {
const bootstrapPath = path.resolve(this.dir, 'config/functions/bootstrap.js');

Expand Down Expand Up @@ -159,9 +169,6 @@ class Strapi {
* Add behaviors to the server
*/
async listen(cb) {
// Mount the HTTP server.
this.server = http.createServer(this.app.callback());

// handle port in use cleanly
this.server.on('error', err => {
if (err.code === 'EADDRINUSE') {
Expand Down

0 comments on commit b5bfe60

Please sign in to comment.