From 6ab1a328abbb5a89187d24bea982c00700431da3 Mon Sep 17 00:00:00 2001 From: Alex Wild Date: Tue, 11 Jul 2017 17:18:03 +0200 Subject: [PATCH] prepare for new server. Closes #65 --- .gitignore | 5 +++- .../com.chachachat.chachachat.plist | 24 ----------------- ecosystem.json | 17 ++++++++++++ package.json | 26 +++++++++---------- server.js | 19 ++------------ start_local.sh | 5 ---- start_production.sh | 7 ----- 7 files changed, 36 insertions(+), 67 deletions(-) delete mode 100644 config/LaunchDaemons/com.chachachat.chachachat.plist create mode 100644 ecosystem.json delete mode 100755 start_local.sh delete mode 100644 start_production.sh diff --git a/.gitignore b/.gitignore index b512c09..08ecabf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -node_modules \ No newline at end of file +.DS_Store +node_modules +log/* +!log/.gitkeep diff --git a/config/LaunchDaemons/com.chachachat.chachachat.plist b/config/LaunchDaemons/com.chachachat.chachachat.plist deleted file mode 100644 index 0efc18a..0000000 --- a/config/LaunchDaemons/com.chachachat.chachachat.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - Label - com.chachachat.chachachat - UserName - admin - EnvironmentVariables - - PATH - /usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin - NODE_ENV - production - - ProgramArguments - - sh - /chachachat/start_production.sh - - RunAtLoad - - - diff --git a/ecosystem.json b/ecosystem.json new file mode 100644 index 0000000..08b2053 --- /dev/null +++ b/ecosystem.json @@ -0,0 +1,17 @@ +{ + "apps" : [ + { + "name": "chachachat", + "script": "server.js", + "instances": 1, + "cwd": ((process.env.NODE_ENV === "production") ? "" : "/Users/" + process.env.USER) + "/chachachat/", + "max_memory_restart": "512M", + "log_file": ((process.env.NODE_ENV === "production") ? "" : "/Users/" + process.env.USER) + "/chachachat/log/chachachat.log", + "out_file": "/dev/null", + "error_file": ((process.env.NODE_ENV === "production") ? "" : "/Users/" + process.env.USER) + "/chachachat/log/err.log", + "log_date_format": "YYYY-MM-DD HH:mm Z", + "merge_logs": true, + "watch": false + } + ] +} diff --git a/package.json b/package.json index 70e2d10..fbcbc90 100644 --- a/package.json +++ b/package.json @@ -9,22 +9,22 @@ "start": "node server.js" }, "dependencies": { - "express": "3.5.0", - "express-session": "latest", - "mongoose": "~3.8.22", - "socket.io": "0.9.14", - "passport": "0.2.0", + "apn": "1.7.8", + "async": "2.5.0", + "connect-redis": "2.5.1", + "express": "3.21.2", + "express-session": "1.15.3", + "jade": "1.11.0", + "mongoose": "3.8.40", + "passport": "0.3.2", "passport-local": "1.0.0", - "jade": "1.3.1", - "connect-redis": "2.0.0", - "passport.socketio": "3.0.1", - "winston": "0.7.3", - "underscore": "1.6.0", - "async": "0.9.0", - "apn": "latest" + "passport.socketio": "3.7.0", + "socket.io": "0.9.19", + "underscore": "1.8.3", + "winston": "1.1.2" }, "devDependencies": { - "debug" : "latest" + "debug": "latest" }, "repository": { "type": "git", diff --git a/server.js b/server.js index e9663c4..b3073a5 100644 --- a/server.js +++ b/server.js @@ -209,30 +209,15 @@ app.post('/register', function(req, res, next) { }); }); - -var server; -if (app.get('env') === 'production') { - -debugger - - server = http.createServer(app); -} else { - var credentials = { - key: fs.readFileSync('config/chachachat-key.pem'), - cert: fs.readFileSync('config/chachachat-cert.pem') - }; - server = https.createServer(credentials, app); // to be able to test local; -} - - +var server = http.createServer(app); var io = socketio.listen(server); + io.set('authorization', passportSocketIO.authorize({ cookieParser: express.cookieParser, key: 'connect.sid', secret: sessionSecret, store: sessionStore })); - app.io = io; // Bootstrap controllers diff --git a/start_local.sh b/start_local.sh deleted file mode 100755 index 4737a0f..0000000 --- a/start_local.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -mongod & -redis-server /usr/local/etc/redis.conf & -node server.js \ No newline at end of file diff --git a/start_production.sh b/start_production.sh deleted file mode 100644 index 53fb5cf..0000000 --- a/start_production.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -root="/chachachat" - -cd $root -forever stop $root/server.js > /dev/null | exit 0 -forever start --append --workingDir $root -p $root -l log/forever.log -o log/out.log -e log/err.log server.js