Skip to content

Commit

Permalink
Remove config dep and include socket.io-client in bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
snawbel committed Jun 26, 2016
1 parent 85dddbd commit bce43ed
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 40 deletions.
18 changes: 0 additions & 18 deletions config/default.js

This file was deleted.

13 changes: 0 additions & 13 deletions config/production.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"scripts": {
"build": "webpack --config webpack.config.js",
"start": "npm run build && node server",
"dev": "npm run build && NODE_ENV=development node server",
"deploy": "git push heroku master"
},
"dependencies": {
Expand All @@ -15,10 +16,10 @@
"angular-ui-bootstrap": "^0.13.4",
"angular-ui-router": "^0.2.18",
"bootstrap": "^3.1.1",
"config": "^1.21.0",
"express": "^4.14.0",
"morgan": "^1.7.0",
"path": "^0.12.7",
"socket.io-client": "^1.4.8",
"underscore": "^1.8.3"
},
"devDependencies": {
Expand Down
17 changes: 17 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const productionConfig = {
apiBase: 'http://api.storypalette.net/v1/',
socketBase: 'http://api.storypalette.net/',
environment: 'production',
port: 8881,
};

const developmentConfig = {
apiBase: 'http://localhost:8880/v1/',
socketBase: 'http://localhost:8880/',
environment: 'local',
port: 8881,
}

const config = (process.env.NODE_ENV === 'development') ? developmentConfig : productionConfig;

module.exports = config;
5 changes: 3 additions & 2 deletions server/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// by injecting a javascript object `window.env`
module.exports = function(config) {
var info = {
apiBase: config.api.baseUrl,
//environment: config.server.environment
apiBase: config.apiBase,
socketBase: config.socketBase,
environment: config.environment
};

return function(req, res) {
Expand Down
2 changes: 0 additions & 2 deletions server/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<title>Storypalette Touch Performer</title>
<meta charset="utf-8">

<!-- socket.io client js is served by storypalette-server -->
<script src="http://api.storypalette.net:8890/socket.io/socket.io.js"></script>

<!-- server config info is served by storypalette-server -->
<script src="/env.js"></script>
Expand Down
7 changes: 4 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Storypalette Player server
// Serves the interface files for the native app.

var config = require('config');
var config = require('./config');
var path = require('path');
var express = require('express');
//var favicon = require('serve-favicon');
Expand All @@ -26,9 +26,10 @@ app.get('/*', function(req, res) {
});

// Start server.
var port = process.env.PORT || 8890;
var port = process.env.PORT || config.port;
const mode = process.env.NODE_ENV || 'production';

app.listen(port, function() {
console.log('storypalette-player available at port', port);
console.log(`storypalette-player in ${mode} mode at port ${port}`);
});
module.exports = app;
1 change: 1 addition & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ angular.module('sp.player', [
}
},
socket: function(user, connection, utils, auth) {
console.log('user', user);
var ns = utils.getSocketNamespace(user);
var room = user.roomId;
var token = auth.getToken();
Expand Down
1 change: 1 addition & 0 deletions src/common/spConnection/connection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import btFordSocketIo from 'angular-socket-io';
import io from 'socket.io-client';

angular.module('spConnection', [
'btford.socket-io'
Expand Down
3 changes: 2 additions & 1 deletion src/common/spUtils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ angular.module('spUtils', [])

// Socket utils.
getSocketNamespace: function(user) {
return 'http://api.storypalette.net:8890/' + user.organisation._id;
// TODO: hacky
return `${window.env.socketBase}${user.organisation._id}`;
},

// Returns an array of available rooms for a (non-player user)
Expand Down

0 comments on commit bce43ed

Please sign in to comment.