Skip to content

Commit

Permalink
#14 Use NODE env to configure node server/client
Browse files Browse the repository at this point in the history
  • Loading branch information
Nisheeth Kashyap committed Sep 6, 2013
1 parent 39c6da8 commit 3f3ce27
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 59 deletions.
2 changes: 0 additions & 2 deletions Readme.md
Expand Up @@ -88,7 +88,6 @@ window.ConsoleIO.config = {

// optionals
secure: false,
minify: true,

nativeConsole: true,
web: false, // true to display web console
Expand Down Expand Up @@ -126,7 +125,6 @@ define(['console.io'], function (consoleio) {

// optionals
secure: false,
minify: true,

nativeConsole: true,
web: false,
Expand Down
2 changes: 1 addition & 1 deletion build.bat
@@ -1 +1 @@
grunt default > debug-log.txt
grunt default > build-log.txt
4 changes: 2 additions & 2 deletions dist/app/console.app.css
@@ -1,11 +1,11 @@
/**
* Name: console.io
* Version: 0.2.0
* Version: 0.2.0-1
* Description: Javascript Remote Web Console
* Website: http://nkashyap.github.io/console.io/
* Author: Nisheeth Kashyap
* Email: nisheeth.k.kashyap@gmail.com
* Date: 2013-09-04
* Date: 2013-09-06
*/

code {
Expand Down
4 changes: 2 additions & 2 deletions dist/app/console.app.js
@@ -1,11 +1,11 @@
/**
* Name: console.io
* Version: 0.2.0
* Version: 0.2.0-1
* Description: Javascript Remote Web Console
* Website: http://nkashyap.github.io/console.io/
* Author: Nisheeth Kashyap
* Email: nisheeth.k.kashyap@gmail.com
* Date: 2013-09-04
* Date: 2013-09-06
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/app/console.app.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/app/console.app.min.js

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions dist/client/console.io.js
@@ -1,15 +1,15 @@
/**
* Name: console.io
* Version: 0.2.0
* Version: 0.2.0-1
* Description: Javascript Remote Web Console
* Website: http://nkashyap.github.io/console.io/
* Author: Nisheeth Kashyap
* Email: nisheeth.k.kashyap@gmail.com
* Date: 2013-09-04
* Date: 2013-09-06
*/

var ConsoleIO = ("undefined" === typeof module ? {} : module.exports);
ConsoleIO.version = "0.2.0";
ConsoleIO.version = "0.2.0-1";

(function(){

Expand Down Expand Up @@ -364,7 +364,7 @@ ConsoleIO.version = "0.2.0";
return styleNode.join("; ");
};

util.getUrl = function getUrl(name, uncompressed) {
util.getUrl = function getUrl(name) {
var config = exports.getConfig(),
url = config.url,
last = url.length - 1,
Expand All @@ -374,11 +374,6 @@ ConsoleIO.version = "0.2.0";
url = url.substr(0, last);
}

if (config.minify && !uncompressed) {
fileUrl = fileUrl.replace('.css', '.min.css');
fileUrl = fileUrl.replace('.js', '.min.js');
}

url += (config.base.length > 0 ? '/' + config.base : '/') + fileUrl;

return url;
Expand Down Expand Up @@ -2046,7 +2041,6 @@ ConsoleIO.version = "0.2.0";
url: '',
base: '',
secure: false,
minify: true,

html2canvas: "plugins/html2canvas.js",
//"console.io": "console.io.js",
Expand Down Expand Up @@ -2123,7 +2117,7 @@ ConsoleIO.version = "0.2.0";
if (exports.util.foundRequireJS()) {
global.require(["socket.io"], setUp);
} else {
exports.util.require(exports.util.getUrl("socket.io", true), setUp);
exports.util.require(exports.util.getUrl("socket.io"), setUp);
}
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions dist/client/console.io.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/client/console.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "xconsole.io",
"version": "0.2.0",
"version": "0.2.0-1",
"project": "console.io",
"subdomain": "console.io",
"description": "Javascript Remote Web Console",
Expand Down
2 changes: 1 addition & 1 deletion server/config.js
Expand Up @@ -30,7 +30,7 @@

var config = {

domain: null, //'.bbdev1.com',
domain: null,

/** express configurations **/
express: {
Expand Down
70 changes: 48 additions & 22 deletions server/main.js
Expand Up @@ -19,31 +19,57 @@ function main() {
fs = require('fs'),
manager = require('./manager');


function Workers() {
var app,
base = '/',
opts = {};

if (config.https.enable) {
if (config.https.pfx) {
opts.pfx = fs.readFileSync(config.https.pfx);
function getApp(config) {
var expressApp;
if (!config.https.enable) {
expressApp = express().http().io();
} else {
opts.key = fs.readFileSync(config.https.key);
opts.cert = fs.readFileSync(config.https.certificate);
// This is necessary only if the client uses the self-signed certificate.
if (config.https.ca) {
opts.ca = fs.readFileSync(config.https.ca);
if (config.https.pfx) {
opts.pfx = fs.readFileSync(config.https.pfx);
} else {
opts.key = fs.readFileSync(config.https.key);
opts.cert = fs.readFileSync(config.https.certificate);
// This is necessary only if the client uses the self-signed certificate.
if (config.https.ca) {
opts.ca = fs.readFileSync(config.https.ca);
}
}

if (opts.requestCert) {
opts.requestCert = config.https.requestCert;
}

expressApp = express().https(opts).io();
}

if (opts.requestCert) {
opts.requestCert = config.https.requestCert;
return expressApp;
}

function getURL(url, base) {
url = url.replace(base, '/');

if (process.env.NODE_ENV === 'production') {
url = url.replace('.js', '.min.js');
url = url.replace('.css', '.min.css');
}

app = express().https(opts).io();
} else {
app = express().http().io();
return url;
}


//if node env is not defined then set it to 'production'
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'production';
}

//if env port no is not define then use one defined in config
if (!process.env.PORT) {
process.env.PORT = app.get('port-number');
}

// If this node.js application is hosted in IIS, assume it is hosted
Expand All @@ -56,13 +82,16 @@ function main() {
config.io.development.set.push({ 'resource': base + 'socket.io' });
config.io.production.set.push({ 'resource': base + 'socket.io' });


//get expressjs app
app = getApp(config);

// configuration
configure(app, 'development', config.express);
configure(app, 'production', config.express);
configure(app.io, 'development', config.io);
configure(app.io, 'production', config.io);


// Setup your sessions, just like normal.
app.use(base, express.cookieParser());
app.use(base, express.session({ secret: app.get('session-key') }));
Expand All @@ -82,15 +111,12 @@ function main() {

//console client routes
function client(req, res) {
res.sendfile('./dist/client' + req.originalUrl.replace(base, '/'));
res.sendfile('./dist/client' + getURL(req.originalUrl, base));
}

app.use(base + 'console.io.js', client);
app.use(base + 'console.io.min.js', client);
app.use(base + 'console.css', client);
app.use(base + 'console.min.css', client);
app.use(base + 'plugins/html2canvas.js', client);
app.use(base + 'plugins/html2canvas.min.js', client);

//userdata app routes
app.use(base + 'userdata/export', function download(req, res) {
Expand All @@ -104,14 +130,14 @@ function main() {

//console app routes
app.use(base, function app(req, res) {
res.sendfile('./dist/app' + req.originalUrl.replace(base, '/'));
res.sendfile('./dist/app' + getURL(req.originalUrl, base));
});

// initialize connection manager
manager.setUp(app);

// listen to port
app.listen(process.env.PORT || app.get('port-number'));
app.listen(process.env.PORT);

//set GUID cookie handler
(function setUpCookieHandler(express, app) {
Expand Down Expand Up @@ -237,7 +263,7 @@ function main() {
}(express, app));

//display remote ui url information
console.log(app.get('title') + ' is run at ' + (config.https.enable ? 'https' : 'http') + '://localhost:' + (process.env.PORT || app.get('port-number')));
console.log(app.get('title') + ' is run at ' + (config.https.enable ? 'https' : 'http') + '://localhost:' + process.env.PORT);
}

Workers();
Expand Down
3 changes: 1 addition & 2 deletions src/client/config.js
Expand Up @@ -15,7 +15,6 @@
url: '',
base: '',
secure: false,
minify: true,

html2canvas: "plugins/html2canvas.js",
//"console.io": "console.io.js",
Expand Down Expand Up @@ -92,7 +91,7 @@
if (exports.util.foundRequireJS()) {
global.require(["socket.io"], setUp);
} else {
exports.util.require(exports.util.getUrl("socket.io", true), setUp);
exports.util.require(exports.util.getUrl("socket.io"), setUp);
}
}
} else {
Expand Down
7 changes: 1 addition & 6 deletions src/client/util.js
Expand Up @@ -349,7 +349,7 @@
return styleNode.join("; ");
};

util.getUrl = function getUrl(name, uncompressed) {
util.getUrl = function getUrl(name) {
var config = exports.getConfig(),
url = config.url,
last = url.length - 1,
Expand All @@ -359,11 +359,6 @@
url = url.substr(0, last);
}

if (config.minify && !uncompressed) {
fileUrl = fileUrl.replace('.css', '.min.css');
fileUrl = fileUrl.replace('.js', '.min.js');
}

url += (config.base.length > 0 ? '/' + config.base : '/') + fileUrl;

return url;
Expand Down

0 comments on commit 3f3ce27

Please sign in to comment.