Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit df2a5399a2e64424a90816893257934a1203e9f9 @darashi darashi committed Jan 30, 2012
Showing with 84 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +8 −0 README.md
  3. +25 −0 package.json
  4. +1 −0 public/index.html
  5. +44 −0 server.coffee
@@ -0,0 +1,6 @@
+build
+.lock-wscript
+node_modules
+lib/nroonga_bindings.node
+test/tmp
+deps
@@ -0,0 +1,8 @@
+## nroonga-httpd
+
+Yet another [groonga](http://groonga.org) http server implementation.
+nroonga-http is built on the top of [nroonga](http://nroonga.github.com).
+
+### How to use
+
+ % coffee server.coffee target_database
@@ -0,0 +1,25 @@
+{
+ "name": "nroonga-httpd",
+ "description": "Yet another groonga http server implementation",
+ "version": "0.0.1",
+ "author": "Yoji Shidara <dara@shidara.net>",
+ "keywords": ["groonga", "nroonga", "fulltext", "search", "database"],
+ "homepage" : "http://nroonga.github.com/",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/nroonga/nroonga-httpd.git"
+ },
+ "bugs": {
+ "url": "http://github.com/nroonga/nroonga-httpd/issues"
+ },
+ "dependencies": {
+ "nroonga":"",
+ "express":"",
+ "coffee-script":"",
+ "optimist":""
+ },
+ "scripts": {
+ "start": "node_modules/coffee-script/bin/coffee server.coffee",
+ },
+ "main": "./lib/nroonga"
+}
@@ -0,0 +1 @@
+This is nroonga-httpd.
@@ -0,0 +1,44 @@
+express = require('express')
+nroonga = require('nroonga')
+opt = require('optimist')
+ .usage('groonga http server.\nUsage: $0')
+ .options
+ p:
+ alias: 'port'
+ integer: true
+ default: 3000
+ h:
+ alias: 'help'
+ describe: 'show this help'
+ 'document-root':
+ describe: 'document root path'
+ default: __dirname + '/public'
+argv = opt.argv
+
+if argv.help
+ opt.showHelp()
+ process.exit(0)
+
+dbPath = argv._[0]
+db = if dbPath?
+ new nroonga.Database(dbPath)
+else
+ new nroonga.Database()
+
+app = express.createServer()
+app.use express.logger()
+app.use express.static(argv['document-root'])
+
+app.get '/d/:command', (req, res) ->
+ startAt = new Date()
+ db.command req.params.command, req.query, (error, data) ->
+ doneAt = new Date()
+ duration = startAt - doneAt
+ if error?
+ console.log(error)
+ res.send([[-1, startAt, duration, error.toString(), []]], 500)
+ else
+ res.send([[0, startAt, duration], data])
+
+app.listen(argv.p)
+console.log "Server listening at port #{argv.p}."

0 comments on commit df2a539

Please sign in to comment.