Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added favicon support to user your if its present or our ours if not.…

… updated package version
  • Loading branch information...
commit 22b6ecebfd006ac1e863be12204a754d1117343f 1 parent 27f862d
Simeon Bateman authored
View
BIN  bin/favicon.ico
Binary file not shown
View
3  package.json
@@ -2,7 +2,7 @@
"author": "Simeon Bateman <simeon@simb.net> (http://www.simb.net)"
, "name": "httpster"
, "description": "Simple http server for local content"
- , "version": "0.2.1"
+ , "version": "0.3.0"
, "repository": "git://github.com/SimbCo/httpster.git"
, "keywords": ["http", "web", "server"]
, "main": "./lib/httpster"
@@ -18,7 +18,6 @@
, "devDependencies": {
"should": "*"
, "mocha": "*"
- , "coffee-script": "*"
}
, "engines": {
"node": "*"
View
34 src/fav.coffee
@@ -0,0 +1,34 @@
+fs = require("fs")
+crypto = require("crypto")
+
+module.exports = favicon = (path, options) ->
+ options = options or {}
+ maxAge = options.maxAge or 86400000
+ icon = undefined
+ # favicon cache
+ favicon = (req, res, next) ->
+ if "/favicon.ico" is req.url
+ if icon
+ res.writeHead 200, icon.headers
+ res.end icon.body
+ else
+ path = __dirname + "/../bin" unless fs.existsSync(path + "/favicon.ico")
+ fs.readFile path + "/favicon.ico", (err, buf) ->
+ return next(err) if err
+ icon =
+ headers:
+ "Content-Type": "image/x-icon"
+ "Content-Length": buf.length
+ ETag: "\"" + md5(buf) + "\""
+ "Cache-Control": "public, max-age=" + (maxAge / 1000)
+
+ body: buf
+
+ res.writeHead 200, icon.headers
+ res.end icon.body
+
+ else
+ next()
+
+md5 = (str, encoding) ->
+ crypto.createHash("md5").update(str).digest encoding or "hex"
View
2  src/server.coffee
@@ -12,6 +12,7 @@ exec = require('child_process').exec
connect = require('connect')
path = "./"
port = undefined
+fav = require('./fav')
program
.version('0.1.0')
@@ -26,6 +27,7 @@ startDefaultServer = (port, path) ->
app = connect()
+ app.use( fav(path) )
app.use connect.static(path)
app.use connect.logger(format:"dev")
app.use connect.errorHandler(dumpExceptions: true, showStack: true)
Please sign in to comment.
Something went wrong with that request. Please try again.