major update to latest yang-js/yang-express to now support hot-pluggable data models during runtime. also enable complete event-propagation for changes to the data models on a per-model basis. fixes #2 and #3. documentation updated to reflect initial support for openapi/swagger 2.0 specification auto-generation. near-complete support for websocket/socket.io will enable dynamic change push to the client application
diff --git a/src/api/server.coffee b/src/api/server.coffee
index 0d68b7d..e9dbd4e 100644
--- a/src/api/server.coffee
+++ b/src/api/server.coffee
@@ -8,20 +8,23 @@
#
yang = require('yang-js')
-argv = require('minimist')(process.argv.slice(2))
-app = require('yang-express') {
- models: [
- yang.require 'cord-core'
- yang.require 'xos-core'
- ]
- controllers: [
- 'restjson'
- 'socket-io'
- ]
- views: [
+app = require('yang-express') ->
+ @set 'pkginfo', require('../../package.json')
+ @set 'initial state', require('../../sample-data.json')
+ @enable 'openapi', 'restjson', 'websocket'
+
+ cord = @link yang.require('cord-core')
+ xos = @link yang.require('xos-core')
+
+ cord.on 'update', (prop) ->
+ console.log "[#{prop.path}] got updated, should consider persisting the change somewhere"
+
+module.exports = app
- ]
- data: require '../../sample-data.json'
-}
-app.run argv.port || 5050
+# only start if directly invoked
+if require.main is module
+ path = require('path')
+ argv = require('minimist')(process.argv.slice(2))
+ argv.port ?= 5050
+ app.listen argv.port