Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Changes to make things work with the new proxy.js and app.js splitting. #41

Closed
wants to merge 9 commits into from
This page is out of date. Refresh to see the latest.
View
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "public_bejesus"]
+ path = public_bejesus
+ url = git@github.com:DanBUK/bejesus-web.git
View
4 app.js
@@ -10,7 +10,7 @@ http://nodester.com
var express = require('express'),
url = require('url'),
sys = require('sys'),
- config = require("./lib/config"),
+ config = require("./config"),
middle = require('./lib/middle');
process.on('uncaughtException', function (err) {
@@ -21,7 +21,7 @@ var myapp = express.createServer();
myapp.configure(function(){
myapp.use(express.bodyDecoder());
- myapp.use(express.staticProvider(__dirname + '/public'));
+ myapp.use(express.staticProvider(config.opt.public_html_dir));
myapp.use(middle.error());
});
View
1  example_config.js
@@ -8,6 +8,7 @@ exports.opt = {
home_dir: '/var/nodester',
app_dir: '/var/nodester/nodester',
hosted_apps_subdir: 'hosted_apps', // This should be a subfolder of home_dir - TODO - Change this..
+ public_html_dir: '/var/nodester/nodester/public',
proxy_table_file: '/var/nodester/var/proxy_table.json',
tl_dom: 'testnodester.com',
api_dom: 'api.testnodester.com',
View
4 lib/3rdparty/node-http-proxy.js
@@ -97,7 +97,7 @@ exports.createServer = function () {
}
});
- server.setMaxListeners(maxEventListeners);
+ // server.setMaxListeners(maxEventListeners);
server.on('close', function () {
if (proxyTable) proxyTable.close();
});
@@ -482,4 +482,4 @@ HttpProxy.prototype = {
};
exports.HttpProxy = HttpProxy;
-exports.ProxyTable = ProxyTable;
+exports.ProxyTable = ProxyTable;
View
15 proxy/proxy.js
@@ -6,13 +6,13 @@ This app runs on port 80 and forwards traffic to the appropriate node app
*/
-var httpProxy = require('../lib/3rdparty/http-proxy'),
- https = require('https'),
+var httpProxy = require('../lib/3rdparty/node-http-proxy'),
url = require('url'),
sys = require('sys'),
fs = require('fs'),
lib = require('../lib/lib'),
- daemontools = require('daemon-tools')
+ daemontools = require('daemon-tools'),
+ exec = require('child_process').exec,
config = require('../config')
;
@@ -20,13 +20,13 @@ lib.update_proxytable_map(function (err) {
if (err) {
console.log("err: " + JSON.stringify(err));
} else {
- // var proxy = httpProxy.createServer({router: config.opt.proxy_table_file});
- var proxy = httpProxy.createServer({router: config.opt.proxy_table_file, silent: false, hostname_only: true});
+ var proxy = httpProxy.createServer({router: config.opt.proxy_table_file, silent: true, hostname_only: true});
proxy.listen(80);
proxy.addListener('updateRoutes', function () {
console.log('updateRoutes fired');
});
if (config.opt.enable_ssl === true) {
+ var https = require('https');
var options = {
ca: fs.readFileSync(config.opt.app_dir + '/' + config.opt.ssl_ca_file),
key: fs.readFileSync(config.opt.app_dir + '/' + config.opt.ssl_key_file),
@@ -40,7 +40,10 @@ lib.update_proxytable_map(function (err) {
httpSsl.listen(443);
sys.puts('Nodester started on port 443');
}
- daemontools.setreuid_username(config.opt.userid);
+ var child = exec('id -u ' + config.opt.userid, function (err, stdout, stderr) {
+ daemontools.setreuid(parseInt(stdout));
+ sys.puts('Switched to ' + config.opt.userid + '.');
+ });
sys.puts('Nodester started on port 80');
}
});
1  public_bejesus
@@ -0,0 +1 @@
+Subproject commit 05133ffccf3eed311456dc08050d3c55375fb8bc
View
6 scripts/launch_app.sh
@@ -7,5 +7,7 @@ APPSTART="${4}";
APPPORT="${5}";
APPHOST="${6}";
APPNAME="${7}";
-
-exec /usr/local/bin/node ${BASEDIR}/scripts/launch_chrooted_app.js ${USERN} ${APPHOME} ${APPSTART} ${APPPORT} ${APPHOST} ${APPNAME};
+export HOME=/var/nodester;
+ID=$( id -u ${USERN} );
+echo $ID;
+exec /usr/bin/node ${BASEDIR}/scripts/launch_chrooted_app.js ${ID} ${APPHOME} ${APPSTART} ${APPPORT} ${APPHOST} ${APPNAME};
View
1  scripts/launch_chrooted_app.js
@@ -28,7 +28,6 @@ logger.setup(app_name, function (err) {
*/
daemontools.chroot(chroot_dir);
var pid = daemontools.start(true);
- // daemontools.setreuid_username(effective_user);
daemontools.setreuid(effective_user);
daemontools.lock("/.app.pid");
fs.chmodSync("/.app.pid", 0666);
View
56 scripts/migrate-views.js
@@ -5,30 +5,36 @@ var request = require('request');
var h = {accept:'application/json', 'content-type':'application/json'};
var couch_loc = "http://" + config.opt.couch_user + ":" + config.opt.couch_pass + "@" + config.opt.couch_host + ":" + config.opt.couch_port + "/" + config.opt.couch_prefix + "_";
-var all_view_uri = couch_loc + 'apps' + '/_design/nodeapps'
-var design_document = {"language": "javascript","views": {"all": {"map": "function(doc) { emit(doc.username, doc);}"}}}
+var all_views = [
+ {uri: couch_loc + 'apps' + '/_design/nodeapps', design: {"language": "javascript","views": {"all": {"map": "function(doc) { emit(doc.username, doc);}"}}}}
+ ,{uri: couch_loc + 'aliasdomains' + '/_design/aliasdomains', design: {"language": "javascript","views": {"all": {"map": "function(doc) { emit(doc.username, doc);}"}}}}
+];
-request({uri:all_view_uri, method:'GET', headers:h}, function (err, response, body) {
+for (var i in all_views) {
+ var all_view_uri = all_views[i].uri;
+ var design_document = all_views[i].design;
+ request({uri:all_view_uri, method:'GET', headers:h}, function (err, response, body) {
+ if (response.statusCode == 404) {
+ request({uri:all_view_uri, method:'PUT', headers:h, body:JSON.stringify(design_document)}, function (err, response, body){
+ if (response.statusCode == 201) {
+ console.log(all_view_uri + " : all view created");
+ } else {
+ console.log(sys.inspect(body));
+ console.log(sys.inspect(err));
+ }
+ });
+ } else {
+ doc = JSON.parse(body);
+ design_document._rev = doc._rev;
+ request({uri:all_view_uri + '?rev=' + doc._rev, method:'PUT', headers:h, body:JSON.stringify(design_document)}, function (err, response, body){
+ if (response.statusCode == 201) {
+ console.log(all_view_uri + ": all view updated");
+ } else {
+ console.log(sys.inspect(body));
+ console.log(sys.inspect(err));
+ }
+ });
+ }
+ });
+}
- if (response.statusCode == 404) {
- request({uri:all_view_uri, method:'PUT', headers:h, body:JSON.stringify(design_document)}, function (err, response, body){
- if (response.statusCode == 201) {
- console.log("all view created");
- } else {
- console.log(sys.inspect(body));
- console.log(sys.inspect(err));
- }
- });
- } else {
- doc = JSON.parse(body);
- design_document._rev = doc._rev;
- request({uri:all_view_uri + '?rev=' + doc._rev, method:'PUT', headers:h, body:JSON.stringify(design_document)}, function (err, response, body){
- if (response.statusCode == 201) {
- console.log("all view updated");
- } else {
- console.log(sys.inspect(body));
- console.log(sys.inspect(err));
- }
- });
- }
-});
Something went wrong with that request. Please try again.