/*
 * syndicate-g
 * https://github.com/petarov/syndicate-g
 *
 * The MIT License (MIT)
 * Copyright (c) 2013 Petar Petrov
 */
"use strict";

var config = require('./config.js');
var syng = require('./lib/syndicate-g.js')(config).create();

var express = require('express');
var app = express();
var server = require('http').createServer(app);

app.configure(function() {
    // app.locals.pretty = true;
    app.use(express.bodyParser());
    app.use(express.static(__dirname + '/public'));
    app.use(express.logger());
    app.set('views', __dirname + '/public');
    app.engine('html', require('ejs').renderFile);
});

app.get('/', function(request, response) {
    response.render('index.html', {pretty: true});
});

app.get('/fetch', function(request, response) {
    fetch(request, response);
});

app.get('/fetch/:id', function(request, response) {
    fetch(request, response);
});

function fetch(request, response) {
    var maxResults = request.query.maxResults;
    if (!/^\-?([0-9]+|Infinity)$/.test(maxResults))
        maxResults = config.gplus.maxResults;

    // console.log(request.query);
    var gid = request.query.gid || request.params.id;

    syng.fetch(gid, {'maxResults': maxResults}, function(err, data) {
        if (err) {
            console.log(err);
            response.send(err.code, err);
            return;
        }
        response.writeHead(200, {'Content-Type': 'text/xml'});
        response.end(data); 
    });    
}

app.get('/clear/:id', function(request, response) {
    syng.deleteCache(request.params.id, function(err) {
        if (err) {
            console.log(err);
            response.send(err.code, err);
            return;
        }
        response.send(200);
    });
});

app.get('*', function(request ,response) {
    response.status(404).render('404.html', {pretty: true});
});

server.listen(config.server.port, config.server.host, function() {
    console.log("[Srv] It's on, brother.");
});

/**
 * Exports
 */
module.exports = app;
@@ -233,17 +233,16 @@
 eate();%0A
-%0A
 var expr
@@ -340,40 +340,82 @@
 p);%0A
-%0Aapp.configure(function() %7B%0A    
+var bodyParser = require('body-parser');%0Avar morgan = require('morgan');%0A%0A
 // a
@@ -439,28 +439,24 @@
 = true;%0A
-    
 app.use(
 express.
@@ -447,24 +447,16 @@
 app.use(
-express.
 bodyPars
@@ -457,25 +457,53 @@
 dyParser
-());%0A    
+.urlencoded(%7B%0A  extended: true%0A%7D)); %0A
 app.use(
@@ -546,20 +546,16 @@
 ));%0A
-    
 app.use(
 expr
@@ -554,31 +554,29 @@
 use(
-express.logger());%0A    
+morgan('combined'));%0A
 app.
@@ -612,20 +612,16 @@
 blic');%0A
-    
 app.engi
@@ -658,20 +658,16 @@
 erFile);
-%0A%7D);
 %0A%0Aapp.ge
@@ -753,24 +753,25 @@
  true%7D);%0A%7D);
+ 
 %0A%0Aapp.get('/

Fix express 4 issues