I started an application in AngularJS couple of weeks ago. All my configuration variable are stored in a constant like this:
/**
* defines constants for application
*/
define(['angular'], function (ng) {
'use strict';
return ng.module('app.constants', [])
.constant('CONFIG', {
node_port: 3700,
api_host: 'api.acme.local',
node_host: 'acme.com',
facebook_app_id: 'xxxxxxxxx'
});
});
The problem I have is that I need to change this value each time I want to push my application in stage. I'm using rsync so I could ignore this file and modify it once on the stage server. It might not be the best solution but it would work.
Now recently I've added a nodejs server to my application using express and socket.io, which mean I now have to setup the client in my angularjs application and the server.js.
Because I'm using requirejs I also need to update the path for socket.io.
requirejs:
paths: {
'jquery': 'bower_components/jquery/dist/jquery.min',
...
'socketio': 'http://acme.local:3700/socket.io/socket.io'
},
and my server.js:
var express = require('express'),
debug = true,
http = require('http'),
_ = require('underscore'),
server = express(),
port = 3700,
api_host = 'api.acme.local',
io = require('socket.io').listen(server.listen(port), {log: debug});
...
var options = {
hostname: api_host,
port: 80,
path: '/courses',
method: 'GET'
};
var req = http.request(options, function(res) {
var output = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
output += chunk;
});
...
So basically I'm ending up with duplicated variable for my node application and angular application, plus I need to toggle values between dev and stage variables values.
What would be the best solution to this problem?
Thanks
UPDATE 1
Just found out that requirejs has a failover option for the path, so for now I'm using it:
paths: {
'jquery': 'bower_components/jquery/dist/jquery.min',
...
'socketio': [
'http://stage.acme.com:3700/socket.io/socket.io',
'http://acme.local:3700/socket.io/socket.io'
]
},
Still investigating how to do it properly