-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 679eaef
Showing
68 changed files
with
1,197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.vagrant | ||
.DS_Store | ||
thumbs.db | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# Deployed apps should consider commenting this line out: | ||
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git | ||
node_modules | ||
client/public/javascript/* | ||
client/public/stylesheets/* | ||
|
||
# Vagrant | ||
.vagrant | ||
|
||
# development scripts | ||
*.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Eirik L. Vullum | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Hearsay Live News App | ||
===================== | ||
|
||
#### Introduction: | ||
Introduction | ||
|
||
![express basic application](http://s29.postimg.org/osrdfy24n/preview.png "Express Basic Application") | ||
|
||
#### Built with: | ||
* [node.js](http://www.nodejs.org/) | ||
* [express](http://www.expressjs.com/) | ||
* [gulp](http://www.gulpjs.com/) | ||
* [convict](http://github.com/mozilla/node-convict/) | ||
* [browserify](http://www.browserify.org/) | ||
* [envify](http://github.com/hughsk/envify/) | ||
* [reactify](https://github.com/andreypopp/reactify) | ||
* [react](http://facebook.github.io/react/) | ||
* [sass](http://sass-lang.com/) | ||
* [bootstrap](http://getbootstrap.com/) | ||
* [fontawesome](http://fortawesome.github.io/Font-Awesome/) | ||
* [jquery](http://www.jquery.com/) | ||
|
||
#### Testing: | ||
* [jest](http://facebook.github.io/jest/) | ||
|
||
#### Dependencies: | ||
* [nodejs](http://www.nodejs.org/) | ||
* [mongodb](http://www.mongodb.org/) | ||
* [redis](http://redis.io/) | ||
|
||
#### Install dependencies: | ||
* `brew/apt-get install nodejs` | ||
* `brew/apt-get install redis` | ||
* `brew/apt-get install mongodb` | ||
* `npm install -g mocha` | ||
* `npm install -g gulp` | ||
* `npm install` | ||
|
||
#### Environment variables: | ||
* `PORT` - Port exposed by this component. | ||
* example: `3000` | ||
* `DEBUG` - Debug output (* for all) (optional) | ||
* example: `*` | ||
* `NODE_ENV` - Environment ('development', 'staging', 'production') | ||
* example: `development` | ||
* `CLIENT_API_PATH` - Path to the client REST api (relative) | ||
* example: `/api` | ||
* `APPSECRET` - Application session secret | ||
* example: `sOmeCrAzYhAsH894372` | ||
* `SESSION_KEY` - Application session secret (optional) | ||
* example: `express.sid` (defaults to `connect.sid`) | ||
* `REDIS_URL` - Redis url (including authentication) | ||
* example: `redis://user:pass@localhost:6379` | ||
* `REDIS_DB` - Redis database number (optional) | ||
* example: `1` | ||
* `REDIS_SESSION_PREFIX` - Prefix for redis session entries (optional) | ||
* example: `sess:` | ||
* `MONGO_URL` - MongoDB url (including authentication) | ||
* example: `mongodb://user:pass@localhost:27017/mydatabase` | ||
|
||
#### Run tests: | ||
* `npm test` or `mocha -R spec` | ||
|
||
#### Run the application: | ||
* set environment variables | ||
* `gulp` | ||
* (create a shellscript with the above for convenience if you want) | ||
* navigate your browser to `http://localhost:3000` (or whatever port you chose for `PORT`) | ||
|
||
#### Development shellscript example: | ||
```sh | ||
#!/bin/sh | ||
export PORT=3000 \ | ||
export DEBUG="*" \ | ||
export NODE_ENV="production" \ | ||
export APPSECRET="somecrazyhash" \ | ||
export CLIENT_API_PATH="/api" \ | ||
export SESSION_KEY="express.sid" \ | ||
export MONGO_URL="mongodb://localhost/express-basic-app" \ | ||
export REDIS_URL="redis://localhost:6379" \ | ||
|
||
gulp | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Unit Tests | ||
========== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// tests | ||
describe('SomeFunctionality', function(){ | ||
describe('#function()', function() { | ||
it('should do what it is supposed to do', function() { | ||
expect(1).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('#function()', function() { | ||
it('should do what it is supposed to do', function() { | ||
expect(1).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('#function()', function() { | ||
it('should do what it is supposed to do', function() { | ||
expect(1).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('#function()', function() { | ||
it('should do what it is supposed to do', function() { | ||
expect(1).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('#function()', function() { | ||
it('should do what it is supposed to do', function() { | ||
expect(1).toBe(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// dependencies | ||
var http = require('http'); | ||
var express = require('express'); | ||
var mongoose = require('mongoose'); | ||
var session = require('express-session'); | ||
var RedisStore = require('connect-redis')(session); | ||
var cookieParser = require('cookie-parser'); | ||
var app = express(); | ||
|
||
// config and setup helpers | ||
var helpers = require('./helpers')(); | ||
var config = require('./config'); | ||
var setup = require('./setup'); | ||
var common = require('hearsay-common'); | ||
|
||
// database connection | ||
setup.db(mongoose, config); | ||
|
||
// setup session store | ||
var sessionStore = setup.sessions(RedisStore, config); | ||
|
||
// configure express | ||
setup.configureExpress({ | ||
express: express, | ||
session: session, | ||
store: sessionStore, | ||
cookieParser: cookieParser, | ||
dir: __dirname | ||
}, app, config); | ||
|
||
// http (wrapper in case you plan to use socket.io at some point) | ||
var server = http.createServer(app); | ||
|
||
// app modules | ||
var ipc = require('./modules/ipc')(0); | ||
var models = common.models(mongoose); | ||
var services = require('./services')(models, helpers); | ||
var middleware = require('./middleware')(); | ||
var handlers = require('./handlers')(services, helpers); | ||
|
||
// initialize routes | ||
require('./routes')(app, express, middleware, handlers, config); | ||
|
||
// express error handling | ||
setup.handleExpressError(app, helpers); | ||
|
||
// run application | ||
setup.run(server, config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Client Side Application | ||
======================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @jsx React.DOM | ||
*/ | ||
'use strict'; | ||
|
||
// config | ||
var config = require('./config'); | ||
var api = require('./modules/api')(config); | ||
|
||
// dependencies | ||
var React = require('react'); | ||
var ReactAsync = require('react-async'); | ||
var superagent = require('superagent'); | ||
|
||
// custom components | ||
var Counter = require('./modules/components/counter'); | ||
var LikeButton = require('./modules/components/like-button'); | ||
var Ticker = require('./modules/components/ticker'); | ||
var Time = require('./modules/components/time'); | ||
var Head = require('./modules/components/head'); | ||
var Header = require('./modules/components/header'); | ||
|
||
// Main page component (this is asyncronous) | ||
var App = React.createClass({ | ||
// mixins | ||
mixins: [ReactAsync.Mixin], | ||
|
||
// static methods | ||
statics: { | ||
getAsyncContent: function (callback) { | ||
superagent.get('http://localhost:3000/api/resource', function (err, res) { | ||
callback(err, res ? res.body : null); | ||
}); | ||
}.bind(this) | ||
}, | ||
|
||
// the initial state of the component (this.type refers to a static method) | ||
getInitialStateAsync: function (callback) { | ||
//this.type.getAsyncContent(callback); // fetch async content (disabled for now) | ||
callback(null, this.props); // set the input props as state (equal to 'return this.props' in getInitialState, but async) | ||
}, | ||
|
||
// main rendering function (uses the state of the component, not the props) | ||
render: function() { | ||
return ( | ||
<html> | ||
<Head title={this.state.title} description={this.state.description} /> | ||
<body id="reactapp"> | ||
<Header /> | ||
<div className="container"> | ||
<div className="jumbotron text-center"> | ||
<h1>React Demo Components</h1> | ||
</div> | ||
</div> | ||
|
||
<div className="MainPage container"> | ||
|
||
<Counter initialCount={10} /> | ||
<Time startTime={this.state.startTime} /> | ||
<LikeButton liked={false} /> | ||
<Ticker offset={0} interval={1000} /> | ||
|
||
</div> | ||
</body> | ||
</html> | ||
); | ||
} | ||
}); | ||
|
||
module.exports = App; | ||
|
||
// If the file is processed by the browser, it should mount itself to the document and 'overtake' the markup from the server without rerendering | ||
if (typeof window !== 'undefined') { | ||
// enable the react developer tools when developing (loads another 450k into the DOM..) | ||
if (config.environment == 'development') { | ||
window.React = require('react'); | ||
} | ||
|
||
window.onload = function () { | ||
React.renderComponent(App(), document); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
exports = module.exports = { | ||
environment: process.env.NODE_ENV, | ||
port: process.env.PORT, | ||
api: { | ||
url: process.env.CLIENT_API_PATH | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
exports = module.exports = function (request, path) { | ||
return function (query, callback) { | ||
request | ||
.get(path) | ||
.query(query) | ||
.end(function (error, res) { | ||
if (error) return callback(error); | ||
if (res.status != 200) return callback('unexpected response code: ' + res.status); | ||
if (!res.body) return callback('no body'); | ||
|
||
callback(null, res.body); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports = module.exports = function (request, path) { | ||
return { | ||
get: require('./get')(request, path) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var request = require('superagent'); | ||
|
||
exports = module.exports = function (config) { | ||
return { | ||
entries: require('./entries')(request, config.api.url + '/entries') | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** @jsx React.DOM */ | ||
|
||
'use strict'; | ||
|
||
var React = require('react'); | ||
|
||
module.exports = React.createClass({ | ||
displayName: 'Counter', | ||
|
||
getInitialState: function () { | ||
return {count: this.props.initialCount}; | ||
}, | ||
|
||
handleClick: function () { | ||
this.setState({count: this.state.count + 1}); | ||
}, | ||
|
||
render: function () { | ||
return ( | ||
<div className='well' onClick={this.handleClick}> | ||
Click me to increment! {this.state.count} | ||
</div> | ||
); | ||
} | ||
}); |
Oops, something went wrong.