Last active
January 14, 2017 15:27
-
-
Save JBreit/c0f3ea5177fff5388e2628eb1e768b47 to your computer and use it in GitHub Desktop.
Raven NodeJS Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = function (request, response) { | |
'use strict'; | |
response.write('test'); | |
request.pipe(response); | |
}; | |
module.exports = app; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"host": "127.0.0.1", | |
"port": 443, | |
"ssl": { | |
"enabled": true, | |
"agent": false, | |
"key": "./server/config/ssl/server.pem", | |
"certificate": "./server/config/ssl/server.crt" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createServer = require('./server').createServer, | |
app = require('./app'), | |
defaults = require('./server/config/defaults'), | |
server = undefined; | |
function listen(err) { | |
'use strict'; | |
/* | |
this is where child process module gets implemented. research more on the subject | |
*/ | |
if (err) { | |
process.exit(1); | |
} | |
var addr = server.address(); | |
var bind = typeof addr === 'string' | |
? 'pipe ' + addr | |
: 'port ' + addr.port; | |
console.log('server listening at: ' + defaults.host + ':' + defaults.port); | |
console.log('bind: %s', bind); | |
} | |
server = createServer(defaults, app, listen); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
http = require('http'), | |
https = require('https'), | |
normalizePort = require('./utils').normalizePort; | |
function extractCredentialsFrom(settings) { | |
'use strict'; | |
var secure = settings.ssl !== undefined && settings.ssl.enabled === true; | |
if (secure) { | |
return { | |
key: fs.readFileSync(settings.ssl.key), | |
certificate: fs.readFileSync(settings.ssl.certificate) | |
}; | |
} | |
} | |
function configure(settings) { | |
'use strict'; | |
return extractCredentialsFrom(settings); | |
} | |
function start(app, options) { | |
'use strict'; | |
if (options) { | |
return https.createServer(options, app); | |
} else { | |
return http.createServer(app); | |
} | |
} | |
exports.createServer = function (settings, app, callback) { | |
'use strict'; | |
var options = configure(settings), | |
port = normalizePort(settings.port); | |
return start(app, options).listen(port, callback); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.normalizePort = function (val) { | |
'use strict'; | |
var port = parseInt(val, 10); | |
if (isNaN(port)) { | |
return val; | |
} | |
if (port >= 0) { | |
return port; | |
} | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment