Skip to content

Commit

Permalink
404 & 500 pages added
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudnode committed Sep 25, 2011
1 parent 180bfb2 commit bda01e7
Show file tree
Hide file tree
Showing 18 changed files with 491 additions and 518 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ proxy/.monitor
scripts/gitrepoclone.sh
ssl/*
bin/.nodester.config
*.log
*.log.*
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ myapp.get('/api', function(req, res, next) {
res.redirect('/api.html');
});

myapp.get('/admin', function(req, res, next) {
res.redirect('http://admin.nodester.com');
});
//myapp.get('/admin', function(req, res, next) {
// res.redirect('http://admin.nodester.com');
//});

myapp.get('/irc', function(req, res, next) {
res.redirect('http://irc.nodester.com');
Expand Down
8 changes: 4 additions & 4 deletions bin/app_start.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash

if [ "$USER" != "root" ]; then
echo "Must be root to run this.. Please sudo this command."
exit
fi
#if [ "$USER" != "root" ]; then
# echo "Must be root to run this.. Please sudo this command."
# exit
#fi

cd `dirname $0`

Expand Down
8 changes: 4 additions & 4 deletions bin/app_stop.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash

if [ "$USER" != "root" ]; then
echo "Must be root to run this.. Please sudo this command."
exit
fi
#if [ "$USER" != "root" ]; then
# echo "Must be root to run this.. Please sudo this command."
# exit
#fi

cd `dirname $0`

Expand Down
12 changes: 7 additions & 5 deletions bin/create_user_dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
var exec = require('child_process').exec;
var config = require('../config.js').opt;

var cmd = 'mkdir ' + process.argv[2];

var dirs_string = config.git_home_dir + '/' + process.argv[2] + ' ' + config.apps_home_dir + '/' + process.argv[2];
var cmds = [
'mkdir ' + process.argv[2],
'chown ' + config.userid + ':' + config.userid + ' ' + process.argv[2]
'mkdir ' + dirs_string,
'chown ' + config.git_user + ':' + config.app_uid + ' ' + dirs_string,
'chmod 0775 ' + dirs_string
];

var do_cmd = function () {
if (cmds.length > 0) {
var cmd = cmds.shift();
console.log('Running: ' + cmd);
exec(cmd, function () {
do_cmd();
});
}
};
};
do_cmd();
2 changes: 1 addition & 1 deletion bin/proxy_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ wait
rm ./.nodester.config

export HOME=$HOME_DIR;
export PATH="/usr/local/bin:${HOME}/bin:${PATH}";
export PATH="/usr/local/node-v0.4.0/usr/local/bin:${HOME}/bin:${PATH}";

APPDIR=$APP_DIR/proxy

Expand Down
32 changes: 28 additions & 4 deletions deps/node-http-proxy/node-http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ exports.version = [0, 5, 7];
//
var _agents = {};

var errorHtml = '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">' +
'<head>' +
'<title id="title">{title}</title>' +
'<style stype="text/css">' +
'html { font-family: Arial,Helvetica,sans-serif; }' +
'div { width: 100%; text-align: center; margin-top: 230px; color: #909090; }' +
'</style>' +
'</head>' +
'<body>' +
'<div>' +
'<img src="http://static.jgate.de/img/cloudnode-logo2-light.png" alt="logo" />' +
'<h1>{code}</h1>' +
'<h3>{error}</h3>' +
'</div>' +
'</body>' +
'</html>';

var getErrorPage = function(title, code, error) {
return errorHtml.replace('{title}', title).replace('{code}', code).replace('{error}', error);
};

//
// ### function _getAgent (host, port, secure)
// #### @host {string} Host of the agent to get
Expand Down Expand Up @@ -341,7 +362,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
options = options || {};
options.host = options.host || this.target.host;
options.port = options.port || this.target.port;
options.allow_xforwarded_headers = options.allow_xforwarded_headers || false;
options.allow_xforwarded_headers = options.allow_xforwarded_headers || true;

//
// Check the proxy table for this instance to see if we need
Expand Down Expand Up @@ -386,7 +407,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
req.headers['x-forwarded-port'] = req.connection.remotePort || req.connection.socket.remotePort;
req.headers['x-forwarded-proto'] = res.connection.pair ? 'https' : 'http';
}

util.log(req.method + ': ' + req.headers.host + req.url + ' - ' + req.headers["x-forwarded-for"]);
//
// Emit the `start` event indicating that we have begun the proxy operation.
//
Expand Down Expand Up @@ -418,19 +439,22 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
return;
}

res.writeHead(500, { 'Content-Type': 'text/plain' });
res.writeHead(500, { 'Content-Type': 'text/html' });

if (req.method !== 'HEAD') {
//
// This NODE_ENV=production behavior is mimics Express and
// Connect.
//
res.write(getErrorPage('Application Offline', 500, 'Application is offline'));
/*
if (process.env.NODE_ENV === 'production') {
res.write('Internal Server Error');
}
else {
res.write('An error has occurred: ' + JSON.stringify(err));
}
*/
}

res.end();
Expand Down Expand Up @@ -846,4 +870,4 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
if (options.buffer && !errState) {
options.buffer.resume();
}
};
};
Loading

0 comments on commit bda01e7

Please sign in to comment.