Skip to content

Commit

Permalink
Exported initialize function so server can be controlled externally
Browse files Browse the repository at this point in the history
  • Loading branch information
MKHenson committed Mar 26, 2017
1 parent 74b3c9e commit 43bbb8a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Server as MongoServer, Db } from 'mongodb';
import { Server } from './server';
import { ConsoleManager } from './console/console-manager';
import { prepare } from './db-preparation';
import * as cluster from 'cluster';

let config: Modepress.IConfig | null = null;
const args = yargs.argv;
Expand Down Expand Up @@ -52,7 +53,7 @@ catch ( err ) {
/**
* initialization function to prep DB and servers
*/
async function initialize() {
export async function initialize() {
info( `Attempting to connect to mongodb...` );

const mongoServer = new MongoServer( config!.databaseHost, config!.databasePort, config!.databaseName );
Expand Down Expand Up @@ -82,7 +83,9 @@ async function initialize() {
new ConsoleManager().initialize();
}

// Start the server initialization
initialize().catch(( err: Error ) => {
error( err.message ).then(() => process.exit() );
} );
if ( cluster.isWorker ) {
// Start the server initialization
initialize().catch(( err: Error ) => {
error( err.message ).then(() => process.exit() );
} );
}

0 comments on commit 43bbb8a

Please sign in to comment.