Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pulled out config and app.

  • Loading branch information...
commit 69ff9f862855fcbeac490395e3d66a0fde6243f3 1 parent 4518d85
@jward jward authored
View
11 app.coffee
@@ -0,0 +1,11 @@
+app = require('express')()
+api = require('./api')(app)
+db = require('./db')
+config = require('./config')
+
+db.init(config.db)
+
+api.publish(endpoint: '/1/schemas', handler: require('./apis/schemas-api'))
+api.publish(endpoint: '/1/models/:modelName', handler: require('./apis/models-api'))
+
+module.exports = app
View
11 config.coffee
@@ -0,0 +1,11 @@
+pkg = require('./package.json')
+
+config = {
+ port: 8090
+ version: pkg.version
+ db:
+ server: 'localhost'
+ name: 'test'
+}
+
+module.exports = config
View
8 db.coffee
@@ -4,10 +4,12 @@ class Db
constructor: ()->
init: (config)->
- @db = mongoose.createConnection(config.db.server, config.db.name)
+ @db = mongoose.createConnection(config.server, config.name)
- define: (name, schemaDefinition)->
- schema = new mongoose.Schema(schemaDefinition)
+ model: (name, schema)->
@db.model(name, schema)
+ schema: (schemaDefinition)->
+ new mongoose.Schema(schemaDefinition)
+
module.exports = new Db()
View
8 models/schema.coffee
@@ -1,8 +1,6 @@
db = require('../db')
-Schema = db.define('Schema', {
- name: String
- fields: [{name: String, type: String}]
-})
+Field = db.schema(name: String, type: String)
+Schema = db.schema(name: String, fields: [Field])
-module.exports = Schema
+module.exports = db.model('Schema', Schema)
View
3  package.json
@@ -17,7 +17,8 @@
"devDependencies": {
"mocha": "~1.7.4",
"sinon": "~1.5.2",
- "chai": "~1.4.0"
+ "chai": "~1.4.0",
+ "supertest": "~0.5.1"
},
"optionalDependencies": {},
"engines": {
View
20 server.coffee
@@ -1,23 +1,7 @@
-app = require('express')()
-api = require('./api')(app)
+app = require('./app')
+config = require('./config')
log = require('./log')
-db = require('./db')
-pkg = require('./package.json')
-
-config = {
- port: 8090
- version: pkg.version
- db:
- server: 'localhost'
- name: 'test'
-}
-
-db.init(config)
-
-api.publish(endpoint: '/1/schemas', handler: require('./apis/schemas-api'))
-api.publish(endpoint: '/1/models/:modelName', handler: require('./apis/models-api'))
log.startupMessage(config)
-
app.listen(config.port)
Please sign in to comment.
Something went wrong with that request. Please try again.