Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial setup

  • Loading branch information...
commit 1f175fcf6e9758c240ab61bdba2bd39c08091f11 1 parent 39eefaa
@benjreinhart benjreinhart authored
View
16 .gitignore
@@ -1,14 +1,4 @@
-lib-cov
-*.seed
-*.log
-*.csv
-*.dat
-*.out
-*.pid
-*.gz
-
-pids
-logs
-results
-
+.DS_Store
npm-debug.log
+node_modules
+core/config/environments.yml
View
8 Makefile
@@ -0,0 +1,8 @@
+CWD=$(shell pwd)
+COFFEE=$(CWD)/node_modules/.bin/COFFEE
+
+dev:
+ NODE_ENV=development node $(CWD)/start.js
+
+prod:
+ NODE_ENV=production node $(CWD)/start.js
View
8 components/users/controller.coffee
@@ -0,0 +1,8 @@
+exports.index = (req, res) ->
+ res.send 200, "Hello world from /users!"
+
+exports.show = (req, res) ->
+ res.send 200, 'als;djnadkjsn'
+
+exports.create = (req, res) ->
+ res.send 200, 's;ldnasdkjan'
View
3  core/config/environments.example.yml
@@ -0,0 +1,3 @@
+development:
+ db:
+ host: mongodb://localhost/edits-by-us
View
3  core/config/index.coffee
@@ -0,0 +1,3 @@
+require 'js-yaml'
+
+module.exports = (require './environments.yml')[ process.env.NODE_ENV ]
View
12 core/db/index.coffee
@@ -0,0 +1,12 @@
+config = require "#{ process.env.APP_ROOT }/core/config"
+mongoose = require 'mongoose'
+
+db = mongoose.createConnection config.db.host
+
+db.once 'error', ->
+ console.log 'An error occured while attempting to connect to database'
+
+db.once 'open', ->
+ console.log 'Opened database connection successfully!'
+
+module.exports = { mongoose, db }
View
12 core/db/seeds.coffee
@@ -0,0 +1,12 @@
+async = require 'async'
+
+{ APP_ROOT } = process.env
+
+console.log 'Seeding database...'
+
+
+# async.parallel [], (err) ->
+# throw err if err?
+
+# console.log "Cleared DB"
+# process.exit 0
View
4 core/lib/app.coffee
@@ -0,0 +1,4 @@
+cache = -> cache.app
+cache.set = ((@app) ->).bind cache
+
+module.exports = cache
View
6 core/lib/models/base.coffee
@@ -0,0 +1,6 @@
+module.exports = class Base
+ get: (attr) =>
+ @attributes[attr]
+
+ set: (attr, value) =>
+ @attributes[attr] = value
View
20 core/lib/route_helpers.coffee
@@ -0,0 +1,20 @@
+{APP_ROOT} = process.env
+
+Path = require 'path'
+app = do require "#{ APP_ROOT }/core/lib/app"
+
+requireController = (component) ->
+ require "#{ APP_ROOT }/components/#{ component }/controller"
+
+namespace = (namespace, func) ->
+ routeMethods = {}
+
+ for verb in ['get', 'post', 'put', 'delete']
+ routeMethods[verb] = do (verb) ->
+ (path, cb) ->
+ path = Path.normalize "/#{ namespace }/#{ path }"
+ app[verb] path, cb
+
+ func(routeMethods)
+
+module.exports = { namespace, requireController }
View
14 core/routes.coffee
@@ -0,0 +1,14 @@
+{APP_ROOT} = process.env
+
+{requireController, namespace} = require "#{ APP_ROOT }/core/lib/route_helpers"
+
+Users = requireController 'users'
+
+##########
+# ROUTES #
+##########
+
+namespace 'api', ({ get, post }) ->
+ get '/users', Users.index
+ get '/users/:id', Users.show
+ post '/users', Users.create
View
26 core/server.coffee
@@ -0,0 +1,26 @@
+{APP_ROOT} = process.env
+
+cache = require "#{ APP_ROOT }/core/lib/app"
+express = require 'express'
+
+app = express()
+cache.set(app)
+
+app.configure ->
+ app.set "port", 3000
+
+ app.use express.static "#{ APP_ROOT }/public"
+ app.use express.favicon()
+ app.use express.methodOverride()
+ app.use express.cookieParser("seCret")
+ app.use express.session()
+
+ app.use express.bodyParser()
+ app.use app.router
+
+app.configure "development", ->
+ app.use express.errorHandler()
+
+require './routes'
+
+app.listen(app.get('port'))
View
23 package.json
@@ -0,0 +1,23 @@
+{
+ "name": "edits-by-us",
+ "version": "0.0.0",
+ "description": "Crowd-sourced editing of blog posts",
+ "keywords": ["blogs", "editing"],
+ "author": "Matt Loseke & Ben Reinhart",
+ "dependencies": {
+ "qs": ">=0.5.3",
+ "async": ">=0.2.6",
+ "express": ">=3.1.0",
+ "js-yaml": ">=2.0.3",
+ "mongoose": ">=3.5.7",
+ "coffee-script": ">=1.4.0"
+ },
+ "devDependencies": {},
+ "main": "index",
+ "scripts": {
+ "start": "start.js"
+ },
+ "engines": {
+ "node": "0.8.16"
+ }
+}
View
11 start.js
@@ -0,0 +1,11 @@
+require('coffee-script');
+
+var exec = require('child_process').exec;
+
+exec('pwd', function(err, cwd){
+ cwd = cwd.replace(/\n/, '');
+ process.env.APP_ROOT = cwd;
+
+ require(process.env.APP_ROOT + '/core/server');
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.