Commits

Tom Morton committed f21293a

more work

Comments (0)

Files changed (2)

src/lib/resource.coffee

 		resource = require "/"+path.relative("/","./")+'/resource/'+name
 		return new resource.Resource
 
+	# default behaviour
+	GET: (req,res) =>
+		if req.query.search
+			search = @db.find(JSON.parse(req.query.search))
+		else
+			search = @db.find({})
+		search.exec((e,d) => res.end(d.toString()))
+
 
 
 exports.Resource = Resource

src/lib/server.coffee

 
 handle = (req,res) ->
 	req.url = url.parse(req.url)
-	console.log(req.query)
 	req.url.pathname = req.url.pathname.replace(/^\//g,"").split("/")
-	model = resource.factory(req.url.pathname[0])
-	if req.query.search
-		search = model.db.find(JSON.parse(req.query.search))
-	else
-		search = model.db.find({})
-	search.exec((e,d) => res.end(d.toString()))
-	
+	try
+		model = resource.factory(req.url.pathname[0])
+		switch req.method
+			when "GET" then model.GET(req,res)
+	catch error
+		res.end(JSON.stringify({error:"notfound"}))
 
 start = () ->
 	connect()