[Groonga-commit] nroonga/nroonga [master] add http server example built on Express

Back to archive index

null+****@clear***** null+****@clear*****
2011年 11月 17日 (木) 15:56:10 JST


Yoji SHIDARA	2011-11-17 06:56:10 +0000 (Thu, 17 Nov 2011)

  New Revision: 78365bd0bbc6249a1f049fd376b039e0420674c8

  Log:
    add http server example built on Express

  Added files:
    examples/server.coffee
  Modified files:
    package.json

  Added: examples/server.coffee (+26 -0) 100644
===================================================================
--- /dev/null
+++ examples/server.coffee    2011-11-17 06:56:10 +0000 (79e6c04)
@@ -0,0 +1,26 @@
+express = require('express')
+Nroonga = require('../build/Release/nroonga.node')
+
+db = if process.argv.length > 2
+  new Nroonga.Database(process.argv[2])
+else
+  new Nroonga.Database()
+
+port = 3000
+
+app = express.createServer()
+app.get '/d/:command', (req, res) ->
+  args = [req.params.command]
+  for key, value of req.query
+    args.push("--#{key}")
+    args.push(value)
+
+  command = args.join(' ')
+  db.command command, (error, data) ->
+    if error?
+      res.send(error.toString() + "\n", 400)
+    else
+      res.send(data)
+
+app.listen(port)
+console.log "Server listining at port #{port}."

  Modified: package.json (+3 -0)
===================================================================
--- package.json    2011-11-17 06:56:05 +0000 (4ac6912)
+++ package.json    2011-11-17 06:56:10 +0000 (b01d07c)
@@ -5,6 +5,9 @@
     "coffee-script":"",
     "expresso":""
   },
+  "dependencies": {
+    "express":""
+  },
   "scripts": {
     "test": "expresso"
   }




Groonga-commit メーリングリストの案内
Back to archive index