Comparing version 0.1.1 to 0.2.0
34
index.js
var http = require('http'), | ||
fs = require('fs'), | ||
defaultOpts = {chmod: "777", autoClose: true}; | ||
defaultOpts = { chmod: "777", autoClose: true, autoUnlink: true }; | ||
module.exports = function (onconnect) { | ||
var server = { | ||
getOpts: function (opts) { | ||
if (typeof opts == "string") opts = { path: opts }; | ||
return Object.assign({}, defaultOpts, opts); | ||
}, | ||
unlinkOnExists: function (opts) { | ||
opts = server.getOpts(opts); | ||
if (!opts.autoUnlink) return; | ||
if (!fs.existsSync(opts.path)) return; | ||
return fs.unlinkSync(opts.path); | ||
}, | ||
listen: function (opts, cb) { | ||
if(!cb) cb = function () {}; | ||
if(typeof opts == "string") opts = {path: opts}; | ||
opts = Object.assign({}, defaultOpts, opts); | ||
if(typeof opts.path !== "string") throw "opts.path required"; | ||
opts = server.getOpts(opts); | ||
if (!cb) cb = function () {}; | ||
if (typeof opts.path !== "string") throw "opts.path required"; | ||
server.unlinkOnExists(opts); | ||
server.httpServer.listen(opts.path, function (e) { | ||
if(e) return cb(e); | ||
fs.chmod(opts.path, opts.chmod, function (e) { | ||
if(e) return cb(e); | ||
if(opts.autoClose) server.initAutoClose(opts.onclose); | ||
if (e) return cb(e); | ||
if (opts.autoClose) server.initAutoClose(opts.onclose); | ||
cb(); | ||
@@ -22,2 +32,10 @@ }); | ||
}, | ||
listenPromise: function (opts) { | ||
return new Promise(function(resolve, reject) { | ||
server.listen(opts, function (err) { | ||
if (err) return reject(err); | ||
resolve(); | ||
}); | ||
}); | ||
}, | ||
initAutoClose: function (cb) { | ||
@@ -27,3 +45,3 @@ process.stdin.resume(); | ||
server.httpServer.close(function (e) { | ||
if(cb) cb(); | ||
if (cb) cb(); | ||
process.exit(); | ||
@@ -30,0 +48,0 @@ }); |
{ | ||
"name": "hipc", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "http ipc server", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2875
54