Skip to content

Commit

Permalink
expose variables
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoladj77 committed Feb 24, 2015
1 parent 8b7ce16 commit a111bd8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app.js
Expand Up @@ -15,9 +15,11 @@ mongoose.connection.on('error', function(err) {

mongoose.connect('mongodb://localhost/transactions');
var app = express();
var expose = require('express-expose');
app = expose(app);
var server = require('http').Server(app);
var io = require('socket.io').listen(server);
io.set('origins', 'http://localhost:8080');

require('./services/trending')(io);
// Routes
var api = require('./routes/api');
Expand All @@ -33,6 +35,11 @@ app.set('view engine', 'jade');

app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(function(req, res, next) {
// add an object to expose later
res.locals.expose = {};
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var rek = require('rekuire');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -18,6 +18,7 @@
"socket.io" : "~1.3.4",
"kue": "~0.7.0",
"currency-codes": "~1.1.0",
"async": "~0.9.0"
"async": "~0.9.0",
"express-expose": ">= 0.3.4"
}
}
3 changes: 2 additions & 1 deletion public/js/main.js
@@ -1,4 +1,5 @@
var socket = io('http://localhost:8080');
console.log(data);
var socket = io(data.host);
socket.on('transaction:added', function(data) {
var $tr = $('<tr>');
var country = $('<td>', {text: data.originatingCountry});
Expand Down
3 changes: 2 additions & 1 deletion routes/frontend.js
Expand Up @@ -6,7 +6,6 @@ router.route('/')
var rek = require('rekuire');
var Transaction = rek('models/transaction');
var Trending = rek('models/trending');
console.log('frontend');
async.parallel({
transactions : function(cb) {
Transaction.find({}).limit(20).sort({
Expand All @@ -24,6 +23,8 @@ router.route('/')
}).exec(cb);
}
}, function(err, result) {
console.log(req.headers.host);
res.locals.expose.host = req.headers.host;
res.render('index', {
title : 'Transactions',
results : result.transactions,
Expand Down
2 changes: 2 additions & 0 deletions views/layout.jade
Expand Up @@ -2,6 +2,8 @@ doctype html
html
head
title= title
script.
var data = !{JSON.stringify(expose)}
link(rel='stylesheet', href='/stylesheets/style.css')
link(rel='stylesheet', href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css')
script(src='https://cdn.socket.io/socket.io-1.3.4.js')
Expand Down

0 comments on commit a111bd8

Please sign in to comment.