var express = require('express');
var app = express();
var http = require('http');
var bodyParser = require('body-parser');
var CLModel = require('./models/cl_model');

app.use(express.static('public_html'));
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded

var responseOptions = {
    root: __dirname,
    dotfiles: 'deny',
    headers: {
        'x-timestamp': Date.now(),
        'x-sent': true
    }
};

app.get('/', function (req, res) {
    res.sendFile('views/homepage.html', responseOptions);
});

app.post('/data', function (req, res) {
    console.log(req.body);
    var reqUrl = CLModel.urlFromRequest(req.body);
    if(reqUrl.match(/^http:/)){
        http.get(reqUrl, function(searchResponse) {
            searchResponse.pipe(res);
        }); 
    }
    else{
        res.status(400).send('400 Bad request');
    }
});

app.get('/data/cl.json', function (req, res) {
    res.send(CLModel.model);
});

//The 404 Route (ALWAYS Keep this as the last route)
app.get('*', function(req, res){
    res.status(404).send('404 not found');
});

var server = app.listen(3000, function() {
    var host = server.address().address;
    var port = server.address().port;
    console.log('Wordpop-node app listening at http://%s:%s', host, port);
});
@@ -651,24 +651,27 @@
 , res) %7B%0A   
+ //
  console.log
@@ -1025,16 +1025,588 @@
 );%0A%7D);%0A%0A
+app.get('/data/cl-postbody', function(req, res)%7B%0A    // console.log(%22City requested: %22 + req.query.city);%0A    var reqUrlBase = CLModel.cityUrlFromCity(req.query.city);%0A    if(!reqUrlBase)%7B%0A        res.status(400).send('400 Bad request');%0A    %7D%0A    //test required because if few results craigslist will give links to nearby cities%0A    var reqUrl = req.query.link.match(/%5Ehttp:/) ? req.query.link : reqUrlBase + req.query.link;%0A    // console.log(%22Url requested: %22 + reqUrl);%0A    http.get(reqUrl, function(searchResponse) %7B%0A        searchResponse.pipe(res);%0A    %7D); %0A%0A%7D);%0A%0A
 //The 40

add route to send html page for search post body