<commit_before>http = require 'http'
url = require 'url'
express = require 'express'

controller = require './controller'
map = require './mapping'

# Setup web server express+socket.io
app = express()
server = http.createServer app
io = require('socket.io').listen server

app.use express.bodyParser()

# TODO: move to configuration
app.use express.logger 'dev'
app.use express.static process.argv[3] or 'client'

app.use '/geo*', (req, res, next) ->
  res.header 'Access-Control-Allow-Origin', '*'
  res.header 'Access-Control-Allow-Headers', 'X-Requested-With'
  next()
# end

app.put '/geo', (req, res, next) ->
  geoJson = req.body
  controller.createGeo map.geoJsonToDoc(geoJson), (err) ->
    return next(err) if err?
    io.sockets.emit 'new geo', geoJson
    res.end()

app.get '/geo_put', (req, res, next) ->
  parts = url.parse req.url, true
  {lat, lng} = parts.query
  delete parts.query.lat
  delete parts.query.lng
  doc = {loc:[lng, lat], meta:parts.query}
  controller.createGeo doc, (err, doc) ->
    return next(err) if err?
    io.sockets.emit 'new geo', map.docToGeoJson(doc)
    res.end()

app.get '/geo/:id', (req, res, next) ->
  controller.getGeo req.params.id, (err, geo) ->
    return next(err) if err?
    res.end JSON.stringify map.docToGeoJson geo

app.get '/geo', (req, res, next) ->
  parts = url.parse req.url, true
  find = JSON.parse(parts.query.q) if parts.query.q?
  sort = JSON.parse(parts.query.sort) if parts.query.sort?
  controller.getGeos (err, geos) ->
    return next(err) if err?<commit_msg>Added cohersion for geo_put call, because it is regular URL parameters and not JSON we need to guess data type.<commit_after>http = require 'http'
url = require 'url'
express = require 'express'

controller = require './controller'
map = require './mapping'

cohers = (v) ->
  return Number(v) if not Number.isNaN(Number v)
  return true if v is "true"
  return false if v is "false"
  return new Date(v) if not Number.isNaN(Date.parse v)
  return v

# Setup web server express+socket.io
app = express()
server = http.createServer app
io = require('socket.io').listen server

app.use express.bodyParser()

# TODO: move to configuration
app.use express.logger 'dev'
app.use express.static process.argv[3] or 'client'

app.use '/geo*', (req, res, next) ->
  res.header 'Access-Control-Allow-Origin', '*'
  res.header 'Access-Control-Allow-Headers', 'X-Requested-With'
  next()
# end

app.put '/geo', (req, res, next) ->
  geoJson = req.body
  controller.createGeo map.geoJsonToDoc(geoJson), (err) ->
    return next(err) if err?
    io.sockets.emit 'new geo', geoJson
    res.end()

app.get '/geo_put', (req, res, next) ->
  parts = url.parse req.url, true
  meta = {}
  meta[k] = cohers(v) for k, v of parts.query when not (k in ['lat','lng'])
  {lat, lng} = parts.query
  doc = {loc:[parseFloat(lng), parseFloat(lat)], meta}
  controller.createGeo doc, (err, doc) ->
    return next(err) if err?
    io.sockets.emit 'new geo', map.docToGeoJson(doc)
    res.end()

app.get '/geo/:id', (req, res, next) ->
  controller.getGeo req.params.id, (err, geo) ->
    return next(err) if err?
    res.end JSON.stringify map.docToGeoJson geo

app.get '/geo', (req, res, next) ->
  parts = url.parse req.url, true
  find = JSON.parse(parts.query.q) if parts.query.q?
  sort = JSON.parse(parts.query.sort) if parts.query.sort?
  controller.getGeos (err, geos) ->
    return next(err) if err?
{'fraction_non_alphanumeric': 0.15670767428236673, 'fraction_numerical': 0.0005858230814294083, 'mean_word_length': 3.6086369770580298, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5856592', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1211, 'n_words': 348}