Comparing version 0.8.0 to 0.8.1
@@ -8,2 +8,17 @@ # Nodecaf Changelog | ||
## [v0.8.1] - 2020-02-13 | ||
### Added | ||
- app attribute exposing server port number | ||
- app attribute to toggle conf live reload instead of relying on debug mode | ||
### Changed | ||
- hange global error handler to log errors properly instead of just dumping | ||
- uncaught errors ungly dump to proper log entry | ||
- SIGTER and SIGINT handling to rely on NODE_ENV instead of debug mode | ||
### Removed | ||
- startup and terminate raw console messages in favor of server log entries | ||
- debug mode setting | ||
## [v0.8.0] - 2020-02-11 | ||
@@ -274,1 +289,2 @@ | ||
[v0.8.0]: https://gitlab.com/GCSBOSS/nodecaf/-/tags/v0.8.0 | ||
[v0.8.1]: https://gitlab.com/GCSBOSS/nodecaf/-/tags/v0.8.1 |
@@ -65,2 +65,3 @@ const | ||
this.shouldParseBody = true; | ||
this.watchConfFiles = false; | ||
this.confs = []; | ||
@@ -94,3 +95,2 @@ this.cookieSecret = ''; | ||
// Setup logger. | ||
this.log = new Logger(this); | ||
@@ -104,2 +104,4 @@ | ||
this.port = this.settings.port || (this.ssl ? 443 : 80); | ||
if(this.alwaysRebuildAPI) | ||
@@ -140,4 +142,3 @@ setupAPI.bind(this)(); | ||
async start(){ | ||
if(this.settings.debug) | ||
this.conf.liveReload = true; | ||
this.conf.liveReload = this.watchConfFiles; | ||
@@ -154,10 +155,8 @@ if(this.alwaysRebuildAPI) | ||
: http.createServer(this.express); | ||
let defaultPort = this.ssl ? 443 : 80; | ||
// Start listening on defined port. | ||
let p = this.settings.port || defaultPort; | ||
await new Promise( done => this.server.listen(p, done) ); | ||
await new Promise( done => this.server.listen(this.port, done) ); | ||
this.running = true; | ||
this.log.server(this.settings, 'Started at port %s', true); | ||
this.log.server('Started %s (v%s) at port %s', this.name, this.version, this.port); | ||
} | ||
@@ -171,3 +170,3 @@ | ||
this.running = false; | ||
this.log.server(this.settings, 'Stopped'); | ||
this.log.server('Stopped'); | ||
@@ -177,4 +176,3 @@ // Execute after Stop handler. | ||
if(this.settings.debug) | ||
this.conf.liveReload = false; | ||
this.conf.liveReload = false; | ||
} | ||
@@ -187,4 +185,4 @@ | ||
await this.stop(); | ||
if(typeof conf == 'object' || this.settings.debug){ | ||
this.log.server(conf, 'Reloaded settings'); | ||
if(typeof conf == 'object' || this.watchConfFiles){ | ||
this.log.server('Reloaded settings'); | ||
this.setup(conf || {}); | ||
@@ -191,0 +189,0 @@ } |
@@ -35,9 +35,11 @@ const util = require('util'); | ||
server(conf, msg, port){ | ||
conf = conf || {}; | ||
port = port ? conf.port || this.ssl ? 443 : 80 : ''; | ||
return this.info({ version: this.version, port, class: 'server' }, msg, port); | ||
server(...args){ | ||
this.info({ | ||
version: this.version, | ||
port: this.port, | ||
class: 'server' | ||
}, ...args); | ||
} | ||
err(err, klass){ | ||
err(err, klass, level = 'error'){ | ||
if(!(err instanceof Error)) | ||
@@ -47,3 +49,4 @@ err = new Error(err); | ||
let stack = err.stack.split(/[\r\n]+\s*/g); | ||
return this.error({ | ||
return this[level]({ | ||
...err, | ||
code: err.code, | ||
@@ -50,0 +53,0 @@ type: err.constructor.name, |
@@ -5,18 +5,14 @@ const assert = require('assert'); | ||
/* istanbul ignore next */ | ||
function term(app, debug){ | ||
app.stop(); | ||
if(debug) | ||
function term(){ | ||
this.stop(); | ||
if(!process.env.NODE_ENV) | ||
setTimeout(() => process.exit(0), 1000); | ||
else | ||
console.log('%s is shutting down', app.name); | ||
} | ||
/* istanbul ignore next */ | ||
function die(app, debug, err, origin){ | ||
if(app && app.log) | ||
app.log.fatal({ err: err }, 'fatal error'); | ||
if(debug) | ||
console.log('Unhandled Exception', err, origin); | ||
function die(err){ | ||
if(this.log) | ||
this.log.err(err, 'fatal error', 'fatal'); | ||
else | ||
console.log('Unhandled Exception', err.message, origin); | ||
console.error(err); | ||
process.exit(1); | ||
@@ -35,11 +31,9 @@ } | ||
// Handle signals. | ||
let debug = app.settings.debug || false; | ||
process.on('SIGINT', term.bind(null, app, debug)); | ||
process.on('SIGTERM', term.bind(null, app, debug)); | ||
process.on('uncaughtException', die.bind(null, app, debug)); | ||
process.on('unhandledRejection', die.bind(null, app, debug)); | ||
process.on('SIGINT', term.bind(app)); | ||
process.on('SIGTERM', term.bind(app)); | ||
process.on('uncaughtException', die.bind(app)); | ||
process.on('unhandledRejection', die.bind(app)); | ||
// Starts the app. | ||
await app.start(); | ||
console.log('%s v%s listening at %s', app.name, app.version, app.server.address().port); | ||
} |
{ | ||
"name": "nodecaf", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "Nodecaf is an Express framework for developing REST APIs in a quick and convenient manner.", | ||
@@ -5,0 +5,0 @@ "main": "lib/main.js", |
@@ -193,6 +193,9 @@ # [Nodecaf](https://gitlab.com/GCSBOSS/nodecaf) | ||
When in debug mode (`app.setup({ debug: true })`) changes to loaded config files | ||
will trigger aspplication reloads, so you don't have to manually restart the | ||
whole node process. | ||
```js | ||
app.watchConfFiles = true; | ||
``` | ||
When enabled, changes to loaded config files will trigger application reloads, | ||
so you don't have to manually restart the whole node process. | ||
### Logging | ||
@@ -199,0 +202,0 @@ |
@@ -812,3 +812,4 @@ const assert = require('assert'); | ||
fs.copyFileSync('./test/res/conf.toml', './node_modules/conf.toml'); | ||
let app = new AppServer({ debug: true }); | ||
let app = new AppServer(); | ||
app.watchConfFiles = true; | ||
app.setup('./node_modules/conf.toml'); | ||
@@ -815,0 +816,0 @@ await app.start(); |
79514
501
1225
10