Skip to content

Commit

Permalink
Only create index server instance (a lightly modified restify server)…
Browse files Browse the repository at this point in the history
… if needed
  • Loading branch information
jgoldfar committed Sep 15, 2023
1 parent b02a10a commit 6948140
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/express.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ describe('Acronym API - Express', () => {
server = `http://localhost:${PORT}`;
console.log(`Testing against live Node.JS server at ${server}`);
} else {
// include server from index.js
server = require('./express');
console.log('Testing against server created in specfile');
}
Expand Down
2 changes: 0 additions & 2 deletions src/fastify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ const { Pool } = require('pg');
// npm run --test_live_node_server=true test
const _live_node_server = process.env?.npm_config_test_live_node_server || 'false';
const live_node_server = _live_node_server ? _live_node_server === 'true' : false;
// include server from index.js
const server = require('./fastify');


// usage:
// const t = generateArray();
// const v = generateArray(10, (n) => {return {value: n};});
Expand Down
15 changes: 11 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ server.use(restify.plugins.bodyParser());
server.post('/acronym', routes.Post);
server.put('/acronym/:acronym', routes.Put);

server.listen(parseInt(config.conf.get('PORT')), function() {
console.log('%s listening at %s', server.name, server.url);
});

// the pool will emit an error on behalf of any idle clients
// it contains if a backend error or network partition happens
db.pool.on('error', (err, client) => {
Expand Down Expand Up @@ -75,4 +71,15 @@ server.on('uncaughtException', handleError);
// any other error (fallthru)
server.on('restifyError', handleError);


// run server if used as a module on the command line
if (require.main === module) {
server.listen(parseInt(config.conf.get('PORT')), function() {
console.log('%s listening at %s', server.name, server.url);
});

process.on('SIGINT', doClose);
process.on('exit', doClose);
}

module.exports = server;
1 change: 0 additions & 1 deletion src/koa.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('Acronym API - Koa', () => {
server = `http://localhost:${PORT}`;
console.log(`Testing against live Node.JS server at ${server}`);
} else {
// include server from index.js
server = require('./koa');
console.log('Testing against server created in specfile');
}
Expand Down
1 change: 0 additions & 1 deletion src/plain.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ describe('Acronym API - Plain HTTP', () => {
server = `http://localhost:${PORT}`;
console.log(`Testing against live Node.JS server at ${server}`);
} else {
// include server from index.js
server = require('./plain');
console.log('Testing against server created in specfile');
}
Expand Down
1 change: 0 additions & 1 deletion src/restify.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ if (require.main === module) {

process.on('SIGINT', doClose);
process.on('exit', doClose);

}

module.exports = server;
1 change: 0 additions & 1 deletion src/restify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('Acronym API - Restify', () => {
server = `http://localhost:${PORT}`;
console.log(`Testing against live Node.JS server at ${server}`);
} else {
// include server from index.js
server = require('./restify');
console.log('Testing against server created in specfile');
}
Expand Down

0 comments on commit 6948140

Please sign in to comment.