Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

Commit

Permalink
Changes to enable deployment on heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
ahultgren committed Apr 16, 2015
1 parent 193531a commit 95bb07a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
3 changes: 1 addition & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
web: http-server -p 3005
socket: npm run listen | npm run broadcast
web: npm start
4 changes: 2 additions & 2 deletions app/listener/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
var db = require('../client/dbClient');
var query = require('../query');

exports.start = () => {
exports.start = (echo) => {
db.query(query.createNotifier)
.then(() => {
db.notify('LISTEN watchers', function (msg) {
console.log(msg.payload);
echo(msg.payload);
});
});
};
22 changes: 22 additions & 0 deletions bin/start-all-in-one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

var http = require('http');
var path = require('path');
var express = require('express');
var config = require('../config');
var listener = require('../app/listener');
var WebSocketServer = require('ws').Server;

var app = express().use(express.static(path.join(__dirname, '..', 'public')));
var server = http.createServer(app)
var wss = new WebSocketServer({ server });

listener.start((data) => {
wss.clients.forEach(function each(client) {
client.send(data.toString().trim());
});
});

server.listen(config.get('PORT'), function () {
console.log('Listening on', config.get('PORT'));
});
2 changes: 1 addition & 1 deletion bin/start-listener.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';

require('../app/listener').start();
require('../app/listener').start(console.log.bind(console));
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"name": "omni-matrix",
"version": "1.0.0",
"description": "",
"main": "bin/start-listener",
"main": "bin/start-all-in-one",
"dependencies": {
"babel": "^5.1.9",
"bluebird": "^2.9.24",
"dotenv": "^1.1.0",
"express": "^4.12.3",
"howler": "^1.1.25",
"nconf": "^0.7.1",
"pg": "^4.3.0",
"ws": "^0.7.1"
},
"devDependencies": {
"ws": "^0.7.1",
"http-server": "^0.8.0",
"babelify": "^5.0.4",
"browserify": "^9.0.3",
Expand All @@ -27,10 +26,14 @@
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"devDependencies": {
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"listen": "babel-node .",
"broadcast": "babel-node bin/broadcast"
"start": "babel-node .",
"listen": "babel-node bin/start-listener",
"broadcast": "babel-node bin/broadcast",
"postinstall": "gulp build"
},
"author": "Andreas Hultgren",
"license": "ISC"
Expand Down
3 changes: 2 additions & 1 deletion source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

var thematrix = require('./thematrix');
var blips = require('./blips');
var socket = new WebSocket('ws://localhost:8080');
var port = document.location.port ? ':' + document.location.port : '';
var socket = new WebSocket(`ws://${document.location.hostname}${port}`);
var allowedMessages = ['LoadArticle', 'pageview', 'articleseen'];

socket.onmessage = (e) => {
Expand Down

0 comments on commit 95bb07a

Please sign in to comment.