Skip to content

Commit 4aa76a9

Browse files
author
Adam Dobkin
committed
Basic app structure and build process in place
1 parent 429fa6c commit 4aa76a9

File tree

9 files changed

+167
-0
lines changed

9 files changed

+167
-0
lines changed

Gulpfile.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var gulp = require('gulp');
2+
var gulpLoadPlugins = require('gulp-load-plugins');
3+
var plugin = gulpLoadPlugins();
4+
5+
var copyFiles = [
6+
'./src/**/*',
7+
'!./src/public/css/',
8+
'!./src/public/lib/',
9+
];
10+
11+
//copy dev to build
12+
gulp.task('copyToBuild', function(){
13+
gulp.src(copyFiles).pipe(gulp.dest('./build'));
14+
});
15+
16+
//run browserify
17+
gulp.task('runBrowserify', function(){
18+
gulp.src('/src/public/index.html')
19+
.pipe(plugin.browserify())
20+
.pipe(gulp.dest('/src/public/lib/allLibs.js'));
21+
});
22+
23+
24+
//start dev version using
25+
gulp.task('devStart', function(){
26+
plugin.nodemon({script: 'src/server.js', ignore: 'node_modules/**/*.js'});
27+
});
28+
29+
//start build version
30+
gulp.task('start', plugin.shell.task([
31+
'echo Starting the server!',
32+
'node build/server.js'
33+
]));
34+
35+
//build
36+
gulp.task('build', ['runBrowserify','copyToBuild']);

package.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "learnsyncly",
3+
"version": "0.0.0",
4+
"description": "An app that syncs videos and slideshows",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/LearnSyncly/learnSyncly.git"
8+
},
9+
"author": "",
10+
"license": "UNLICENSED",
11+
"bugs": {
12+
"url": "https://github.com/LearnSyncly/learnSyncly/issues"
13+
},
14+
"homepage": "https://github.com/adamdobkin/learnSyncly#readme",
15+
"dependencies": {
16+
"angular": "^1.4.8",
17+
"angular-ui-router": "^0.2.15",
18+
"browserify": "^12.0.1",
19+
"express": "^4.13.3",
20+
"gulp": "^3.9.0",
21+
"gulp-browserify": "^0.5.1",
22+
"gulp-concat": "^2.6.0",
23+
"gulp-jshint": "^2.0.0",
24+
"gulp-load-plugins": "^1.2.0",
25+
"gulp-nodemon": "^2.0.6",
26+
"gulp-sass": "^2.1.1",
27+
"gulp-shell": "^0.5.1",
28+
"gulp-uglify": "^1.5.1",
29+
"jshint": "^2.8.0",
30+
"mongoose": "^4.3.4",
31+
"socket.io": "^1.4.1"
32+
}
33+
}

src/public/app/app.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
angular.module('lsync', [
2+
'ui.router'
3+
])
4+
.config(function($stateProvider, $urlRouterProvider) {
5+
$urlRouterProvider.otherwise('/');
6+
$stateProvider
7+
.state('entry', {
8+
url: '/',
9+
templateUrl: '/app/entry.html',
10+
controller: 'EntryController'
11+
});
12+
});

src/public/app/entry/entry.html

Whitespace-only changes.

src/public/app/entry/entry.js

Whitespace-only changes.

src/public/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE HTML>
2+
<html data-ng-app='lsync'>
3+
4+
<head>
5+
<meta name="viewport" content="width=device-width">
6+
<link rel="stylesheet" href="/css/allStyles.css">
7+
<link rel="stylesheet" href="/css/lsync.css">
8+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
9+
<title>Learn Syncly</title>
10+
</head>
11+
12+
<body>
13+
<div id="lsyncWrap"data-ui-view>
14+
15+
</div>
16+
<script src="lib/allLibs.js"></script>
17+
</body>
18+
19+
</html>

src/server.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var express = require('express');
2+
var SocketServer = require('socket.io');
3+
var socketController = require('./server/socketController.js');
4+
//new express app
5+
var app = express();
6+
7+
//set port
8+
var port = process.env.PORT || 3000;
9+
10+
//returns http server instance to use with socket.io
11+
var httpServer = app.listen(port, function() {
12+
console.log('Listening on', port);
13+
});
14+
15+
//use https when deployed to heroku
16+
//note headers can be spoofed so this isn't very reliable
17+
//but req.secure doesn't work in heroku
18+
var checkHerokuHTTPS = function(req, res, next) {
19+
var ip = req.connection.remoteAddress.slice(7);
20+
if (ip !== '127.0.0.1') {
21+
if (req.header('x-forwarded-proto') !== 'https') {
22+
return res.redirect('https://' + req.headers.host + req.url);
23+
}
24+
}
25+
next();
26+
};
27+
28+
app.use(checkHerokuHTTPS);
29+
30+
//pass in http server to socket.io which creates a socket.io server
31+
var io = new SocketServer(httpServer);
32+
33+
//use static routes for single page app
34+
app.use(express.static(__dirname + '/../public'));
35+
36+
//call socketContoller passing in socket.io server
37+
socketController(io);

src/server/mongoModel.js

Whitespace-only changes.

src/server/socketController.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//takes a socket io server object
2+
module.exports = function(io){
3+
4+
//event listener that detects socket.io connection event
5+
io.on('connection', function(socket){
6+
console.log('A user connected');
7+
//send back socket id on first connection
8+
socket.emit('connection successful', socket.id);
9+
10+
socket.on('joinroom', function(message) {
11+
socket.join(message.roomname);
12+
io.to(message.roomname).emit('clientjoinroom', message);
13+
});
14+
15+
socket.on('inroom', function(message) {
16+
io.to(message.roomname).emit('clientinroom', message);
17+
});
18+
19+
socket.on('message', function(message) {
20+
io.to(message.roomname).emit('clientmessage', message);
21+
});
22+
23+
socket.on('auth', function(message) {
24+
io.to(message.roomname).emit('clientauth', message);
25+
});
26+
27+
});
28+
29+
30+
};

0 commit comments

Comments
 (0)