<commit_before>var concat = require('concat-stream')
var Router = require('routes-router')
var ecstatic = require('ecstatic')
var fs = require('fs')

var packagejson = require('./package.json')
var utils = require('./utils')
var Database = require('./database')

var APIVERSION = 'v1'
var USER_ID = 1

function get_route(route){
  return ['', APIVERSION, route].join('/')
}

module.exports = function(opts){

  var router = Router()
  var database = Database(opts.storage, opts)

  router.addRoute(get_route('version'), {
    GET: function(req, res){
      res.end(packagejson.version)
    }
  })

  router.addRoute(get_route('projects'), {
    POST: function(req, res){
      utils.slurp_json(req, function(err, data){
        database.create_project(USER_ID, data, function(err, project){
          if(err){
            res.statusCode = 500
            res.end(err)
            return
          }
          res.setHeader('Content-type', 'application/json')
          res.end(JSON.stringify(project))
        })
      })
    }
  })

  router.addRoute(get_route('projects/:id'), {
    GET: function(req, res, opts){
      var projectid = opts.params.id
      database.get_project(USER_ID, projectid, function(err, project){
        if(err){
          res.statusCode = 500
          res.end(err)
          return
        }
        res.setHeader('Content-type', 'application/json')
        res.end(JSON.stringify(project))
      })
    }
  })

  return router
}<commit_msg>added static fileserver for GUI<commit_after>var concat = require('concat-stream')
var Router = require('routes-router')
var ecstatic = require('ecstatic')
var fs = require('fs')

var packagejson = require('./package.json')
var utils = require('./utils')
var Database = require('./database')

var APIVERSION = 'v1'
var USER_ID = 1

function get_route(route){
  return ['', APIVERSION, route].join('/')
}

module.exports = function(opts){

  var router = Router()
  var database = Database(opts.storage, opts)
  var fileServer = ecstatic({ root: __dirname + '/web' })

  router.addRoute(get_route('version'), {
    GET: function(req, res){
      res.end(packagejson.version)
    }
  })

  router.addRoute(get_route('projects'), {
    POST: function(req, res){
      utils.slurp_json(req, function(err, data){
        database.create_project(USER_ID, data, function(err, project){
          if(err){
            res.statusCode = 500
            res.end(err)
            return
          }
          res.setHeader('Content-type', 'application/json')
          res.end(JSON.stringify(project))
        })
      })
    }
  })

  router.addRoute(get_route('projects/:id'), {
    GET: function(req, res, opts){
      var projectid = opts.params.id
      database.get_project(USER_ID, projectid, function(err, project){
        if(err){
          res.statusCode = 500
          res.end(err)
          return
        }
        res.setHeader('Content-type', 'application/json')
        res.end(JSON.stringify(project))
      })
    }
  })

  router.addRoute("/*", fileServer)

  return router
}
{'fraction_non_alphanumeric': 0.1486088379705401, 'fraction_numerical': 0.005237315875613748, 'mean_word_length': 2.7177615571776155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2310577', 'n_tokens_mistral': 965, 'n_tokens_neox': 948, 'n_words': 186}