Use basic HTTP auth #15

Merged
merged 2 commits into from Jun 7, 2014
Jump to file or symbol
Failed to load files and symbols.
+28 −34
Diff settings

Always

Just for now

View
@@ -1 +1 @@
-web: ./bin/colorpicker_server
+web: coffee app.coffee
View
@@ -0,0 +1,11 @@
+Fs = require 'fs'
+Server = require './src/server'
+config = require './src/config'
+logger = require './src/logger'
+
+logger.debug "Loaded config file"
+logger.debug JSON.stringify(config, null, 2)
+
+new Server(config.server.host, config.server.port).run(->
+ logger.info "Express server started on #{config.server.host}:#{config.server.port}"
+)
View
@@ -1,16 +0,0 @@
-#!/usr/bin/env ./node_modules/.bin/coffee
-# -*- mode:coffee -*-
-
-ColorPicker = require '..'
-config = require '../src/config'
-logger = require '../src/logger'
-
-logger.debug "Loaded config file"
-logger.debug JSON.stringify(config, null, 2)
-
-server = ColorPicker.loadServer(
- config.server.host,
- config.server.port
-)
-
-server.run()
View
@@ -1,7 +0,0 @@
-Fs = require 'fs'
-Server = require './src/server'
-
-loadServer = (host, port) ->
- new Server host, port
-
-module.exports.loadServer = loadServer
View
@@ -3,7 +3,7 @@
"version": "0.0.0",
"description": "A Node.js server for socket.io events.",
"scripts": {
- "start": "bin/colorpicker_server",
+ "start": "nodemon app.coffee",
"test": "mocha -w"
},
"repository": {
View
@@ -8,11 +8,19 @@ beagles = []
backbones = []
class Server
+ # set up the express application, including routes and middlewares
+ #
constructor: (@host, @port, @options = {}) ->
@url = "https://#{ @host }:#{ @port }/"
@app = express()
- @app.use express.static(__dirname + "/../public")
+ # use basic HTTP auth and serve the /public dir as /
+ auth = express.basicAuth(process.env.USERNAME || 'foo', process.env.PASSWORD || 'bar')
+ @app.use('/', auth)
+ @app.use('/', express.static(__dirname + '/../public'))
+
+ # stop the server, firing callback upon success
+ #
close: (callback) ->
@httpServer.close(callback)
@@ -23,6 +31,12 @@ class Server
@httpServer = Http.createServer(@app).listen(@port, @host, callback);
@_sio_configure_listener(@httpServer)
+ # sets up the socket.io sockets and namespaces
+ # @note
+ # colorChanged and colorSet both writeColorDataToFile in our
+ # beaglebone client node app. backbone.js takes care of sending
+ # 5x1 color, or 5 individual colors
+ #
_sio_configure_listener: (app) ->
sio = Socket.listen app,
'logger' : logger,
@@ -38,14 +52,6 @@ class Server
logger.info "/backbone CLIENT CONNECTED"
backbones.push socket
- ######################################
- # colorChanged and colorSet both
- # writeColorDataToFile in our
- # beaglebone client node app.
- # backbone.js takes care of sending
- # all 4x 1 color, or 1x 4 colors
- ######################################
-
# when Client is live-previewing color
socket.on 'colorChanged', (data) ->
# send colorChanged data to all beagles