mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-07 05:05:26 +02:00
* Servers now use async listen()
This commit is contained in:
parent
9d1815682d
commit
3864d957c9
7 changed files with 100 additions and 66 deletions
|
@ -5,6 +5,7 @@
|
|||
const Log = require('../../logger.js').log;
|
||||
const { ServerModule } = require('../../server_module.js');
|
||||
const Config = require('../../config.js').get;
|
||||
const { Errors } = require('../../enig_error.js');
|
||||
const {
|
||||
splitTextAtTerms,
|
||||
isAnsi,
|
||||
|
@ -100,19 +101,19 @@ exports.getModule = class GopherModule extends ServerModule {
|
|||
return cb(null);
|
||||
}
|
||||
|
||||
listen() {
|
||||
listen(cb) {
|
||||
if(!this.enabled) {
|
||||
return true; // nothing to do, but not an error
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
const config = Config();
|
||||
const port = parseInt(config.contentServers.gopher.port);
|
||||
if(isNaN(port)) {
|
||||
this.log.warn( { port : config.contentServers.gopher.port, server : ModuleInfo.name }, 'Invalid port' );
|
||||
return false;
|
||||
return cb(Errors.Invalid(`Invalid port: ${config.contentServers.gopher.port}`));
|
||||
}
|
||||
|
||||
return this.server.listen(port);
|
||||
return this.server.listen(port, cb);
|
||||
}
|
||||
|
||||
get enabled() {
|
||||
|
|
|
@ -918,21 +918,26 @@ exports.getModule = class NNTPServerModule extends ServerModule {
|
|||
});
|
||||
}
|
||||
|
||||
listen() {
|
||||
listen(cb) {
|
||||
const config = Config();
|
||||
[ 'nntp', 'nntps' ].forEach( service => {
|
||||
forEachSeries([ 'nntp', 'nntps' ], (service, nextService) => {
|
||||
const server = this[`${service}Server`];
|
||||
if(server) {
|
||||
const port = config.contentServers.nntp[service].port;
|
||||
server.listen(this.listenURI(port, service))
|
||||
.catch(e => {
|
||||
Log.warn( { error : e.message, port }, `${service.toUpperCase()} failed to listen`);
|
||||
return nextService(null); // try next anyway
|
||||
}).then( () => {
|
||||
return nextService(null);
|
||||
});
|
||||
} else {
|
||||
return nextService(null);
|
||||
}
|
||||
},
|
||||
err => {
|
||||
return cb(err);
|
||||
});
|
||||
|
||||
// :TODO: listen() needs to be async. I always should have been...
|
||||
return true;
|
||||
}
|
||||
|
||||
listenURI(port, service = 'nntp') {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
const Log = require('../../logger.js').log;
|
||||
const ServerModule = require('../../server_module.js').ServerModule;
|
||||
const Config = require('../../config.js').get;
|
||||
const { Errors } = require('../../enig_error.js');
|
||||
|
||||
// deps
|
||||
const http = require('http');
|
||||
|
@ -13,6 +14,7 @@ const _ = require('lodash');
|
|||
const fs = require('graceful-fs');
|
||||
const paths = require('path');
|
||||
const mimeTypes = require('mime-types');
|
||||
const forEachSeries = require('async/forEachSeries');
|
||||
|
||||
const ModuleInfo = exports.moduleInfo = {
|
||||
name : 'Web',
|
||||
|
@ -125,23 +127,27 @@ exports.getModule = class WebServerModule extends ServerModule {
|
|||
return cb(null);
|
||||
}
|
||||
|
||||
listen() {
|
||||
let ok = true;
|
||||
|
||||
listen(cb) {
|
||||
const config = Config();
|
||||
[ 'http', 'https' ].forEach(service => {
|
||||
forEachSeries([ 'http', 'https' ], (service, nextService) => {
|
||||
const name = `${service}Server`;
|
||||
if(this[name]) {
|
||||
const port = parseInt(config.contentServers.web[service].port);
|
||||
if(isNaN(port)) {
|
||||
ok = false;
|
||||
return Log.warn( { port : config.contentServers.web[service].port, server : ModuleInfo.name }, `Invalid port (${service})` );
|
||||
Log.warn( { port : config.contentServers.web[service].port, server : ModuleInfo.name }, `Invalid port (${service})` );
|
||||
return nextService(Errors.Invalid(`Invalid port: ${config.contentServers.web[service].port}`));
|
||||
}
|
||||
return this[name].listen(port);
|
||||
}
|
||||
});
|
||||
|
||||
return ok;
|
||||
this[name].listen(port, err => {
|
||||
return nextService(err);
|
||||
});
|
||||
} else {
|
||||
return nextService(null);
|
||||
}
|
||||
},
|
||||
err => {
|
||||
return cb(err);
|
||||
});
|
||||
}
|
||||
|
||||
addRoute(route) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue