Permalink
Browse files

filtering

  • Loading branch information...
1 parent 25a1fee commit d3ab82fbaa999ce48fb908a0929f384f8c7132a2 @martintajur committed Feb 13, 2013
Showing with 11 additions and 1 deletion.
  1. +11 −1 index.js
View
@@ -2,6 +2,7 @@ var Db = require('mysql-activerecord'),
request = require('request'),
moment = require('moment'),
jsdom = require('jsdom'),
+ url = require('url'),
_ = require('underscore'),
http = require('http'),
config = require(__dirname + '/config.json');
@@ -22,9 +23,18 @@ db.query('SELECT * from objects LIMIT 1', function(err, rows, fields) {
if (err) throw err;
var server = http.createServer(function(req, res) {
+ var reqQuery = url.parse(req.url);
db
.order_by('add_time desc')
- .limit(1000)
+ .limit(1000);
+
+ var reqUrl = _.compact(url.parse(req.url).pathname.split('/'));
+
+ if (typeof reqUrl[1] != 'undefined') {
+ db.where('type', reqUrl[1]);
+ }
+
+ db
.get('objects', function(err, rows) {
if (req.url.match(/html/)) {
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Query': db._last_query() });

0 comments on commit d3ab82f

Please sign in to comment.