static-cling
Advanced tools
Comparing version 0.1.6 to 1.0.0
#!/usr/bin/env node | ||
var path = require('path'), | ||
var existsCheck = require('../utils/exists'), | ||
argv = require('optimist').argv, | ||
@@ -8,3 +8,3 @@ cling = require('../lib/static').cling, | ||
file = 'index.html'; | ||
if(argv.p){ | ||
@@ -19,3 +19,3 @@ port = argv.p; | ||
} | ||
path.exists(dir, function (exists) { | ||
existsCheck(dir, function (exists) { | ||
if (exists) { | ||
@@ -29,2 +29,2 @@ console.log('starting to serve files in ' + dir + ' on port ' + port); | ||
var path = require('path'), | ||
http = require('http'), | ||
fs = require('fs'), | ||
url = require('url'), | ||
mime = require('mime'), | ||
sendFileNotFound = function(res){ | ||
res.writeHead(404, { | ||
'Content-Type': 'text/plain' | ||
}); | ||
res.write('404 - File Not Found\n'); | ||
res.end(); | ||
return; | ||
}; | ||
http = require('http'), | ||
fs = require('fs'), | ||
existsCheck = require('../utils/exists'), | ||
url = require('url'), | ||
mime = require('mime'), | ||
sendFileNotFound = function(res){ | ||
res.writeHead(404, { | ||
'Content-Type': 'text/plain' | ||
}); | ||
res.write('404 - ' + res + ' was not found\n'); | ||
res.end(); | ||
return; | ||
}; | ||
var merge = function() { | ||
var i = 0, | ||
hasOwn = Object.prototype.hasOwnProperty, | ||
len = arguments.length, | ||
result = {}, | ||
key, | ||
obj; | ||
for (; i < len; ++i) { | ||
obj = arguments[i]; | ||
for (key in obj) { | ||
if (hasOwn.call(obj, key)) { | ||
result[key] = obj[key]; | ||
} | ||
} | ||
var merge = function() { | ||
var i = 0, | ||
hasOwn = Object.prototype.hasOwnProperty, | ||
len = arguments.length, | ||
result = {}, | ||
key, | ||
obj; | ||
for (; i < len; ++i) { | ||
obj = arguments[i]; | ||
for (key in obj) { | ||
if (hasOwn.call(obj, key)) { | ||
result[key] = obj[key]; | ||
} | ||
} | ||
return result; | ||
} | ||
return result; | ||
}; | ||
var defaults = { | ||
root: '.', | ||
port: 3000, | ||
filename: 'index.html' | ||
root: './', | ||
port: 3000, | ||
filename: 'index.html' | ||
} | ||
var cling = function(options){ | ||
var config = merge(defaults,options); | ||
http.createServer(function (req, res) { | ||
var uri = url.parse(req.url).pathname; | ||
var filename = path.join(config.root, uri); | ||
fs.exists(filename, function (exists) { | ||
if (!exists) { | ||
console.log('no exist'); | ||
return sendFileNotFound(res); | ||
} | ||
var cling = function(options){ | ||
var config = merge(defaults,options); | ||
console.log('starting static server on port ' + config.port ); | ||
http.createServer(function (req, res) { | ||
var uri = url.parse(req.url).pathname; | ||
var filename = path.join(config.root, uri); | ||
existsCheck(filename, function (exists) { | ||
if (!exists) { | ||
return sendFileNotFound(res); | ||
} | ||
if (fs.statSync(filename).isDirectory()) { | ||
filename = path.join(filename, config.filename); | ||
if(!fs.existsSync(filename)){ | ||
return sendFileNotFound(res); | ||
} | ||
} | ||
fs.readFile(filename, 'binary', function (err, file) { | ||
if (err) { | ||
res.writeHead(500, { | ||
'Content-Type': 'text/plain' | ||
}); | ||
res.write(err + '\n'); | ||
res.end(); | ||
return; | ||
} | ||
var type = mime.lookup(filename); | ||
res.writeHead(200, { | ||
'Content-Type': type | ||
}); | ||
res.write(file, 'binary'); | ||
res.end(); | ||
}); | ||
}); | ||
}).listen(config.port); | ||
if (fs.statSync(filename).isDirectory()) { | ||
filename = path.resolve(config.root, path.join(filename, config.filename)); | ||
if(!existsCheck(filename)){ | ||
return sendFileNotFound(res); | ||
} | ||
} | ||
fs.readFile(filename, 'binary', function (err, file) { | ||
if (err) { | ||
res.writeHead(500, { | ||
'Content-Type': 'text/plain' | ||
}); | ||
res.write(err + '\n'); | ||
res.end(); | ||
return; | ||
} | ||
var type = mime.lookup(filename); | ||
res.writeHead(200, { | ||
'Content-Type': type | ||
}); | ||
res.write(file, 'binary'); | ||
res.end(); | ||
}); | ||
}); | ||
}).listen(config.port); | ||
}; | ||
exports.cling = cling; | ||
exports.cling = cling; |
@@ -1,20 +0,36 @@ | ||
{ "name": "static-cling" | ||
, "version": "0.1.6" | ||
, "engines": [ "node >=0.6.0" ] | ||
, "description": "Static file server" | ||
, "author": "Kevin Isom (http://kevinisom.info)" | ||
, "repository" : { | ||
"type" : "git" | ||
, "url" : "git@github.com:Kevnz/Static-Cling.git" | ||
} | ||
, "bugs" : { | ||
{ | ||
"name": "static-cling", | ||
"version": "1.0.0", | ||
"engines": [ | ||
"node >=4.2.0" | ||
], | ||
"description": "Static file server", | ||
"author": "Kevin Isom (http://kevinisom.info)", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:Kevnz/Static-Cling.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Kevnz/Static-Cling/issues" | ||
}, | ||
"scripts": { | ||
"test": "node ./test/static.test.js", | ||
"custom": "node ./test/custom.js" | ||
}, | ||
"keywords": [ | ||
"webserver", | ||
"fileserver" | ||
], | ||
"bin": { | ||
"static": "./bin/static.js" | ||
}, | ||
"dependencies": { | ||
"mime": "^1.3.4", | ||
"optimist": "^0.6.1" | ||
}, | ||
"directories": { | ||
"lib": "./lib/static" | ||
}, | ||
"license": "Unlicense", | ||
"main": "./lib/static" | ||
} | ||
, "keywords" : [ "webserver", "fileserver" ] | ||
, "bin" : { "static" : "./bin/static.js" } | ||
, "dependencies" : { "mime" : ">=0.0.1", "optimist" : ">=0.0.1" } | ||
, "directories": { | ||
"lib": "./lib/static" | ||
} | ||
, "main": "./lib/static" | ||
} |
@@ -0,0 +0,0 @@ #Static Cling |
@@ -0,0 +0,0 @@ var cling = require('../lib/static').cling, |
var cling = require('../lib/static').cling, | ||
port= 8083; | ||
port= 8083; | ||
console.log('starting server with port ' + port) | ||
cling({ port: port }); | ||
cling({ port: port, root: __dirname, filename: 'sample.html' }); | ||
setTimeout(function () { | ||
console.log('shutting down'); | ||
process.exit(0); | ||
}, 20000); | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6719
11
129
1
2
+ Addedmime@1.6.0(transitive)
- Removedmime@4.0.6(transitive)
Updatedmime@^1.3.4
Updatedoptimist@^0.6.1