Peter Lee | df26beb | 2016-07-28 23:42:27 -0700 | [diff] [blame] | 1 | # |
| 2 | # Author: Peter K. Lee (peter@corenova.com) |
| 3 | # |
| 4 | # All rights reserved. This program and the accompanying materials |
| 5 | # are made available under the terms of the Apache License, Version 2.0 |
| 6 | # which accompanies this distribution, and is available at |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | |
Peter K. Lee | af777da | 2016-08-17 04:33:00 -0700 | [diff] [blame] | 10 | Yang = require('yang-js') |
Peter Lee | df26beb | 2016-07-28 23:42:27 -0700 | [diff] [blame] | 11 | |
Peter K. Lee | 29a9514 | 2016-08-13 03:25:18 -0700 | [diff] [blame] | 12 | app = require('yang-express') -> |
Peter K. Lee | af777da | 2016-08-17 04:33:00 -0700 | [diff] [blame] | 13 | @enable 'yangapi' |
| 14 | @enable 'openapi', require('../package.json') |
| 15 | @enable 'restjson' |
| 16 | @enable 'websocket' |
Peter K. Lee | 29a9514 | 2016-08-13 03:25:18 -0700 | [diff] [blame] | 17 | |
Peter K. Lee | af777da | 2016-08-17 04:33:00 -0700 | [diff] [blame] | 18 | data = require('../sample-data.json') |
| 19 | cord = @link Yang.require('cord-core'), data |
| 20 | xos = @link Yang.require('xos-core'), data |
Peter K. Lee | 29a9514 | 2016-08-13 03:25:18 -0700 | [diff] [blame] | 21 | |
| 22 | cord.on 'update', (prop) -> |
| 23 | console.log "[#{prop.path}] got updated, should consider persisting the change somewhere" |
Peter K. Lee | af777da | 2016-08-17 04:33:00 -0700 | [diff] [blame] | 24 | |
Peter K. Lee | 29a9514 | 2016-08-13 03:25:18 -0700 | [diff] [blame] | 25 | module.exports = app |
Peter Lee | df26beb | 2016-07-28 23:42:27 -0700 | [diff] [blame] | 26 | |
Peter K. Lee | 29a9514 | 2016-08-13 03:25:18 -0700 | [diff] [blame] | 27 | # only start if directly invoked |
| 28 | if require.main is module |
Peter K. Lee | 29a9514 | 2016-08-13 03:25:18 -0700 | [diff] [blame] | 29 | argv = require('minimist')(process.argv.slice(2)) |
| 30 | argv.port ?= 5050 |
| 31 | app.listen argv.port |