Merge pull request #790 from strapi/fix/mask

Fix/mask
This commit is contained in:
Jim LAURIE 2018-03-16 17:21:48 +01:00 committed by GitHub
commit 4fb877d9c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 18 deletions

View File

@ -87,6 +87,9 @@ class Strapi extends EventEmitter {
try { try {
this.config = assign(this.config, config) this.config = assign(this.config, config)
// Emit starting event.
this.emit('server:starting');
// Enhance app. // Enhance app.
await this.enhancer(); await this.enhancer();
// Load the app. // Load the app.
@ -100,7 +103,9 @@ class Strapi extends EventEmitter {
// Launch server. // Launch server.
this.server.listen(this.config.port, err => { this.server.listen(this.config.port, err => {
if (err) { if (err) {
console.log(err); this.log.debug(`Server wasn't able to start properly.`);
console.error(err);
return this.stop();
} }
this.log.info('Server started in ' + this.config.appPath); this.log.info('Server started in ' + this.config.appPath);
@ -112,14 +117,16 @@ class Strapi extends EventEmitter {
this.log.debug(`Version: ${this.config.info.strapi} (node v${this.config.info.node})`); this.log.debug(`Version: ${this.config.info.strapi} (node v${this.config.info.node})`);
this.log.info('To shut down your server, press <CTRL> + C at any time'); this.log.info('To shut down your server, press <CTRL> + C at any time');
// Emit started event.
this.emit('server:started');
if (cb && typeof cb === 'function') { if (cb && typeof cb === 'function') {
cb(); cb();
} }
}); });
} catch (e) { } catch (err) {
this.log.debug(`Server wasn't able to start properly.`); this.log.debug(`Server wasn't able to start properly.`);
this.log.error(e); console.error(err);
console.error(e);
this.stop(); this.stop();
} }
} }
@ -136,6 +143,17 @@ class Strapi extends EventEmitter {
}); });
}); });
this.server.on('error', err => {
if (err.code === 'EADDRINUSE') {
this.log.debug(`Server wasn't able to start properly.`);
this.log.error(`The port ${err.port} is already used by another application.`);
this.stop();
return;
}
console.error(err);
});
this.server.destroy = cb => { this.server.destroy = cb => {
this.server.close(cb); this.server.close(cb);

View File

@ -91,6 +91,12 @@ const mountHooks = function (files, cwd) {
}); });
}), }),
resolve (err, results) => {
if (err) {
return reject(err);
}
resolve();
}
); );
}; };

View File

@ -14,16 +14,10 @@ const exposer = require('./exposer');
module.exports = { module.exports = {
loadFile: function(url) { loadFile: function(url) {
try {
// Clear cache. // Clear cache.
delete require.cache[require.resolve(path.resolve(this.config.appPath, url))]; delete require.cache[require.resolve(path.resolve(this.config.appPath, url))];
// Require without cache. // Require without cache.
return require(path.resolve(this.config.appPath, url)); return require(path.resolve(this.config.appPath, url));
} catch (e) {
this.log.error(e);
return {};
}
}, },
setConfig: function(ctx, path, type, loader) { setConfig: function(ctx, path, type, loader) {
@ -123,11 +117,12 @@ module.exports = {
try { try {
if (this.config.uuid) { if (this.config.uuid) {
const publicKey = fs.readFileSync(path.resolve(__dirname, 'resources', 'key.pub')); const publicKey = fs.readFileSync(path.resolve(__dirname, 'resources', 'key.pub'));
const options = { timeout: 1000 };
const [usage, signedHash, required] = await Promise.all([ const [usage, signedHash, required] = await Promise.all([
fetch('https://strapi.io/assets/images/usage.gif'), fetch('https://strapi.io/assets/images/usage.gif', options),
fetch('https://strapi.io/hash.txt'), fetch('https://strapi.io/hash.txt', options),
fetch('https://strapi.io/required.txt') fetch('https://strapi.io/required.txt', options)
]); ]);
if (usage.status === 200 && signedHash.status === 200) { if (usage.status === 200 && signedHash.status === 200) {