Browse files

more robust method of determining env

  • Loading branch information...
1 parent 6d3d8d8 commit 492fd32037b5353f430315422ac3f2adbf95d835 cloudhead committed Aug 2, 2010
Showing with 6 additions and 5 deletions.
  1. +1 −1 bin/thinglerd.sh
  2. +5 −4 src/index.js
View
2 bin/thinglerd.sh
@@ -2,7 +2,7 @@
PID_FILE="/tmp/thinglerd.pid"
SERVER_PATH="$PWD/src/index.js"
-PORT=$2
+PORT=80
if [ "$1" = "start" ]; then
if [ -e $PID_FILE ]; then
View
9 src/index.js
@@ -9,17 +9,18 @@ var todo = require('./todo/collection'),
routes = require('./routes');
var options = {
- port: 8080,
+ port: parseInt(process.argv[2]) || 8080,
lock: '/tmp/thinglerd.pid'
};
-var env = process.env['NODE_ENV'] || 'development';
+var env = (process.env['NODE_ENV'] === 'production' ||
+ options.port === 80) ? 'production' : 'development';
//
// Create a Router object with an associated routing table
//
var router = new(journey.Router)(routes.map, { strict: true });
-var file = new(static.Server)('./pub', { cache: env === 'production' ? 3600 : 0 });
+var file = new(static.Server)('./pub', { cache: env === 'production' ? 3600 : 8 });
this.server = require('http').createServer(function (request, response) {
var body = "";
@@ -51,7 +52,7 @@ this.server = require('http').createServer(function (request, response) {
});
});
-this.server.listen(parseInt(process.argv[2]) || options.port);
+this.server.listen(options.port);
// Write lock file
fs.writeFileSync(options.lock, process.pid.toString() + '\n', 'ascii');

0 comments on commit 492fd32

Please sign in to comment.