Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add static middleware option with CONNECT_STATIC

Setting this to a string will allow the built in connect server to serve static files
from that directory.
  • Loading branch information...
commit fc9a6615bc72c14954e05b490138209d83f83c59 1 parent ae9e939
@omega omega authored
View
3  README.md
@@ -100,6 +100,9 @@ module.exports = (robot) ->
There are functions for GET, POST, PUT and DELETE, which all take a route and
callback function that accepts a request and a response.
+In addition, if you set `CONNECT_STATIC`, the HTTP listener will serve static
+files from this directory.
+
## Testing hubot locally
Install all of the required dependencies by running `npm install`.
View
2  src/robot.coffee
@@ -185,6 +185,7 @@ class Robot
setupConnect: ->
user = process.env.CONNECT_USER
pass = process.env.CONNECT_PASSWORD
+ stat = process.env.CONNECT_STATIC
Connect = require 'connect'
Connect.router = require 'connect_router'
@@ -193,6 +194,7 @@ class Robot
@connect.use Connect.basicAuth(user, pass) if user and pass
@connect.use Connect.bodyParser()
+ @connect.use Connect.static(stat) if stat
@connect.use Connect.router (app) =>
@router =
View
15 test/httpd_test.coffee
@@ -0,0 +1,15 @@
+process.env.CONNECT_STATIC = 'test/static/'
+Tests = require './tests'
+assert = require 'assert'
+helper = Tests.helper()
+require './scripts/test'
+
+helper.adapter.cb = (msg) ->
+ assert.equal 1, helper.sent.length
+ assert.equal "static\n", msg
+ helper.stop()
+
+setTimeout( () ->
+ helper.adapter.receive 'static'
+, 100)
+
View
2  test/robot_test.coffee
@@ -8,7 +8,7 @@ server = require('http').createServer (req, res) ->
res.end "fetched"
server.listen 9001, ->
- assert.equal 5, helper.listeners.length
+ assert.equal 6, helper.listeners.length
assert.equal 0, helper.sent.length
helper.adapter.receive 'test'
View
4 test/scripts/test.coffee
@@ -1,6 +1,10 @@
# Tests hubot listeners
module.exports = (robot) ->
assert = require 'assert'
+ robot.hear /static/i, (msg) ->
+ msg.http('http://127.0.0.1/test').port(process.env.PORT or 8080)
+ .get() (err, res, body) ->
+ msg.send body
robot.hear /test/i, (msg) ->
msg.send "OK"
View
1  test/static/test
@@ -0,0 +1 @@
+static
Please sign in to comment.
Something went wrong with that request. Please try again.