Merge pull request #56 from seripap/eb

Eb
This commit is contained in:
Daniel Seripap 2017-11-17 06:59:41 -05:00 committed by GitHub
commit 229a25ad92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 121 additions and 29 deletions

View File

@ -0,0 +1,3 @@
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm run-script start"

View File

@ -0,0 +1,77 @@
files:
/etc/nginx/conf.d/proxy.conf:
mode: "000644"
owner: root
group: root
content: |
upstream nodejs {
server 127.0.0.1:8081;
keepalive 256;
}
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 8080;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
# Turn off default AWS logging
# access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
# access_log /var/log/nginx/access.log main;
access_log off;
error_log off;
location /socket.io/ {
proxy_pass http://nodejs;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://nodejs;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
gzip on;
gzip_comp_level 4;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location /static {
alias /var/app/current/static;
}
}
/opt/elasticbeanstalk/hooks/configdeploy/post/99_kill_default_nginx.sh:
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash -xe
rm -f /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf
service nginx stop
service nginx start
container_commands:
removeconfig:
command: "rm -f /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"

6
.ebignore Normal file
View File

@ -0,0 +1,6 @@
node_modules/
.DS_STORE
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml

5
.gitignore vendored
View File

@ -3,3 +3,8 @@ node_modules
npm-debug.log
src/public/main.js
src/.secret
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml

View File

@ -21,12 +21,12 @@
"slug": "^0.9.1",
"socket.io": "^1.4.0",
"underscore": "^1.8.3",
"uuid": "^2.0.1"
},
"devDependencies": {
"uuid": "^2.0.1",
"babel-core": "^6.5.2",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.5.2",
"babel-register": "^6.5.2"
},
"devDependencies": {
"compression": "^1.6.0",
"gulp": "^3.9.1",
"gulp-nodemon": "^2.0.6",
@ -54,7 +54,9 @@
"dev": "npm run bundle && gulp start",
"bundle": "gulp bundle",
"test": "npm run bundle && gulp test",
"test-travis": "node_modules/mocha/bin/mocha test/unit/lint.js --compilers js:babel-core/register && node_modules/karma/bin/karma start --single-run && node_modules/nightwatch/bin/nightwatch --test test/acceptance/index.js --config test/acceptance/nightwatch.json -e chrome"
"test-travis": "node_modules/mocha/bin/mocha test/unit/lint.js --compilers js:babel-core/register && node_modules/karma/bin/karma start --single-run && node_modules/nightwatch/bin/nightwatch --test test/acceptance/index.js --config test/acceptance/nightwatch.json -e chrome",
"predeploy": "npm run bundle",
"deploy": "eb deploy --staged"
},
"author": "Daniel Seripap",
"license": "MIT"

View File

@ -44,8 +44,7 @@ function stripName(name) {
}
return chatName;
};
}
app.get('/', (req, res) => generateNewRoom(req, res, stripName(shortid.generate())));

View File

@ -1,7 +1,7 @@
import _ from "underscore";
import { EventEmitter } from "events";
import util from "util";
import uuid from "uuid";
import _ from 'underscore';
import {EventEmitter} from 'events';
import util from 'util';
import uuid from 'uuid';
class Room {
constructor(io = {}, id = {}) {
@ -15,20 +15,20 @@ class Room {
const thisIO = io.of(this._id);
thisIO.on("connection", socket => {
thisIO.on('connection', socket => {
let addedUser = false;
// when the client emits 'new message', this listens and executes
socket.on("new message", data => {
socket.on('new message', data => {
const {username} = socket;
const isRateLimited = this.isRateLimited(username);
if (isRateLimited) {
return thisIO.emit("rated", { username, id: socket.user.id });
return thisIO.emit('rated', {username, id: socket.user.id});
}
// we tell the client to execute 'new message'
socket.broadcast.emit("new message", {
socket.broadcast.emit('new message', {
username,
id: socket.user.id,
message: data.message,
@ -40,7 +40,7 @@ class Room {
});
});
socket.on("add user", data => {
socket.on('add user', data => {
if (addedUser) {
return;
}
@ -58,7 +58,7 @@ class Room {
addedUser = true;
// Broadcast to ALL sockets, including this one
thisIO.emit("user joined", {
thisIO.emit('user joined', {
username: socket.username,
numUsers: this.numUsers,
users: this.users
@ -66,23 +66,23 @@ class Room {
});
// when the client emits 'typing', we broadcast it to others
socket.on("typing", () => {
socket.broadcast.emit("typing", { username: socket.username });
socket.on('typing', () => {
socket.broadcast.emit('typing', {username: socket.username});
});
// when the client emits 'stop typing', we broadcast it to others
socket.on("stop typing", () => {
socket.broadcast.emit("stop typing", { username: socket.username });
socket.on('stop typing', () => {
socket.broadcast.emit('stop typing', {username: socket.username});
});
// when the user disconnects.. perform this
socket.on("disconnect", () => {
socket.on('disconnect', () => {
if (addedUser) {
--this.numUsers;
this.users = _.without(this.users, socket.user);
// echo globally that this client has left
socket.broadcast.emit("user left", {
socket.broadcast.emit('user left', {
username: socket.username,
numUsers: this.numUsers,
users: this.users,
@ -91,13 +91,13 @@ class Room {
// remove room from rooms array
if (this.numUsers === 0) {
this.emit("empty");
this.emit('empty');
}
}
});
// Update user
socket.on("update user", data => {
socket.on('update user', data => {
const newUsername = this.sanitizeUsername(data.newUsername);
if (newUsername.length > 16) {
@ -112,7 +112,7 @@ class Room {
socket.username = user.username = newUsername;
socket.user = user;
thisIO.emit("user update", {
thisIO.emit('user update', {
username: socket.username,
id: socket.user.id
});
@ -151,7 +151,7 @@ class Room {
}
sanitizeUsername(str) {
return str.replace(/[^A-Za-z0-9]/g, "-");
return str.replace(/[^A-Za-z0-9]/g, '-');
}
roomId() {