<commit_before>'use strict'

http = require 'http'

debug = require('debug')
express = require 'express'
Q = require 'q'
_ = require 'underscore'
sensors = require "#{__dirname}/sensors"

{PORT} = require "#{__dirname}/../config"

print = debug 'server'

# app.all '*', (req, res, next) ->
#   res.header "Access-Control-Allow-Origin", "*"
#   res.header "Access-Control-Allow-Methods", "OPTION, GET, OPST, PUT, DELETE"
#   res.header "Access-Control-Allow-Headers", "X-Requested-With"
#   res.header "Access-Control-Allow-Headers", "Content-Type"
#   next()

app = do express

# middleware chain
app.use express.logger()
app.use express.bodyParser()
app.use express.methodOverride()

# routing
app.get '/sensors', (req, res) ->
  res.json 'hello world'
app.post '/sensors', (req, res) ->
  content = req.body

  sensors.insert content.type content, (err, result) ->
    if err
      res.json 405, {errorcode: 405, message: err.message}
    else
      if result.generated_keys?
        timeline.get {id: result.generated_keys[0]}, (err, result) ->
          if err
            res.json 404, {errorcode: 404, message: err.message}
          else
            res.json result
      else
          res.json {message: 'insert failed...'}
#start server

exports.start = () ->
  port = process.env.PORT  or PORT or 8000
  app.listen port
  print "Listening on port #{port}"<commit_msg>fix insert api<commit_after>'use strict'

http = require 'http'

debug = require('debug')
express = require 'express'
Q = require 'q'
_ = require 'underscore'
sensors = require "#{__dirname}/sensors"

{PORT} = require "#{__dirname}/../config"

print = debug 'server'

# app.all '*', (req, res, next) ->
#   res.header "Access-Control-Allow-Origin", "*"
#   res.header "Access-Control-Allow-Methods", "OPTION, GET, OPST, PUT, DELETE"
#   res.header "Access-Control-Allow-Headers", "X-Requested-With"
#   res.header "Access-Control-Allow-Headers", "Content-Type"
#   next()

app = do express

# middleware chain
app.use express.logger()
app.use express.bodyParser()
app.use express.methodOverride()

# routing
app.get '/sensors', (req, res) ->
  res.json 'hello world'
app.post '/sensors', (req, res) ->
  content = req.body

  sensors.insert content.type, content, (err, result) ->
    if err
      res.json 405, {errorcode: 405, message: err.message}
    else
      if result.generated_keys?
        res.json result
      else
        res.json {message: 'insert failed...'}
#start server

exports.start = () ->
  port = process.env.PORT  or PORT or 8000
  app.listen port
  print "Listening on port #{port}"
{'fraction_non_alphanumeric': 0.1562862669245648, 'fraction_numerical': 0.010444874274661509, 'mean_word_length': 3.288557213930348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '1626384', 'n_tokens_mistral': 882, 'n_tokens_neox': 841, 'n_words': 231}