Skip to content

Commit

Permalink
adding command line support
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamjenson committed Jan 25, 2015
1 parent 852da40 commit 0f8df6c
Show file tree
Hide file tree
Showing 45 changed files with 4,631 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ hapiger
To create an event:

```
curl -X POST 'http://localhost:7890/default/event' -d '{person: "p1", action: "likes", thing: "x-men"}'
curl -X POST 'http://localhost:7890/default/event' -d '{person: "p1", action: "likes", thing: "x-men"}' -H "Content-Type: application/json"
```

The `default` namespace is initialized on startup
Expand Down Expand Up @@ -61,14 +61,14 @@ curl -X POST 'http://localhost:7890/namespace/movies'
Then you can add events

```
curl -X POST 'http://localhost:7890/movies/event' -d '{person: "p1", action: "likes", thing: "x-men"}'
curl -X POST 'http://localhost:7890/movies/event' -d '{person: "p1", action: "likes", thing: "x-men"}' -H "Content-Type: application/json"
```


A namespace also has an individual GER configuration which can be set by passing a payload, e.g.

```
curl -X POST 'http://localhost:7890/namespace' -d '{name: "movies", options: {crowd_weight: 1}}'
curl -X POST 'http://localhost:7890/namespace' -d '{name: "movies", options: {crowd_weight: 1}}' -H "Content-Type: application/json"
```

Delete a namespace (and all its events) with
Expand Down
2 changes: 2 additions & 0 deletions bin/hapiger
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env node

require('coffee-script/register')
require('../cli')()
31 changes: 31 additions & 0 deletions cli.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
bb = require 'bluebird'
program = require('commander');
chalk = require 'chalk'

HapiGER = require('./lib/hapi_server.coffee')

cli = ->

program
.version('0.0.1')
.usage('[options]')
.description('start a hapiger server')
.option('-e, --esm <esm>', 'select Event Store Manager [memory, pg, rethinkdb]', 'memory')
.option('-u, --esmurl <options>', 'The url location of the ESM')
.option('-v, --verbose', "More Output", false)
.parse(process.argv);

verbose = program.verbose


hapiger = new HapiGER(
{
esm: program.esm
esmurl: program.esmurl
})
hapiger.initialize()
.then( -> hapiger.start())
.catch((e) -> console.log "ERROR"; console.log e.stack)


module.exports = cli
12 changes: 3 additions & 9 deletions config/environment.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ environment.logging_options = {
}
process.env.PORT=4567

console.log "ENV", process.env.NODE_ENV
switch process.env.NODE_ENV
when "test"

process.env.PORT = 3000
bb.Promise.longStackTraces()
when "production"
else
console.log "ENV", "forcing development"
bb.Promise.longStackTraces()
#AMD
if (typeof define != 'undefined' && define.amd)
define([], -> return environment)
#Node
else if (typeof module != 'undefined' && module.exports)
module.exports = environment;


module.exports = environment
29 changes: 19 additions & 10 deletions lib/hapi_server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ PsqlESM = g.PsqlESM
MemESM = g.MemESM
RethinkDBESM = g.RethinkDBESM

_ = require "underscore"

Utils = {}

Utils.handle_error = (logger, err, reply) ->
Expand All @@ -32,7 +34,20 @@ Utils.handle_error = (logger, err, reply) ->

class HapiGER

initialize: () ->
initialize: (options = {}) ->
@options = _.defaults(options, {
esm: 'memory'
port: 3456
})

switch @options.esm
when 'memory'
@_esm = MemESM
when 'pg'
@_esm = PsqlESM
when 'rethinkdb'
@_esm = RethinkDBESM

bb.try( => @init_server())
.then( => @setup_server())
.then( => @add_server_methods())
Expand All @@ -41,8 +56,7 @@ class HapiGER
init_server: (esm = 'mem') ->
#SETUP SERVER
@_server = new Hapi.Server()
@_server.connection({ port: process.env.PORT });
@_esm = MemESM
@_server.connection({ port: @options.port });
@info = @_server.info
(new @_esm('default')).initialize() #add the default namespace

Expand Down Expand Up @@ -78,8 +92,6 @@ class HapiGER
stop: ->
@stop_server()



load_server_plugin: (plugin, options = {}) ->
d = bb.defer()
@_server.register({register: require(plugin), options: options}, (err) ->
Expand All @@ -105,8 +117,5 @@ class HapiGER
d.promise


#AMD
if (typeof define != 'undefined' && define.amd)
define([], -> return HapiGER)
else if (typeof module != 'undefined' && module.exports)
module.exports = HapiGER;

module.exports = HapiGER
95 changes: 95 additions & 0 deletions node_modules/chalk/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/chalk/node_modules/.bin/has-ansi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/chalk/node_modules/.bin/strip-ansi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/chalk/node_modules/.bin/supports-color

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions node_modules/chalk/node_modules/ansi-styles/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions node_modules/chalk/node_modules/ansi-styles/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0f8df6c

Please sign in to comment.