<commit_before>var express  = require('express');
var http     = require('http');
var path     = require('path');

// This middleware needs to mount routes, so
// it extends the express object.

var _express = express();
this.express = _express;
this.server  = http.createServer(this.express);
_.extend(this, _express);


// Mount all the rest api routes
this.addInitializer(function(opts) {
    debug('Initialize REST api');
    this.post('/api/:model', this.createModel);
    this.get('/api/:model/:id', this.readModel);
    this.put('/api/:model/:id', this.updateModel);
    this.patch('/api/:model/:id', this.updateModel);
    this.del('/api/:model/:id', this.deleteModel);
    this.get('/api/:collection', this.readCollection);
    Graft.reqres.setHandler('model:name', this.modelName);
    Graft.reqres.setHandler('model:load', this.loadModel);
});

Graft.Middleware.on('listen', function(Server) {
    debug('Mounting REST routes');
    Server.use(this);
}, this);

// Implementations for each of the methods
_.extend(this, {
    readModel: function(req, res, next) {
        console.log('start server readModel');
        var send = _.bind(res.send, res);
        var hasModelAndId = req.params.model && req.params.id;
        var modelExists = !!Graft.$models[req.params.model];

        if (!hasModelAndId || !modelExists) { return next(404); }

        var model = new Graft.$models[req.params.model]({
            id: req.params.id
        });

        function fetchModel(attrs) {
            debug('fetching model', req.params.model, req.params.id);
            console.log('fetching model', req.params.model, req.params.id);
            console.log('fetching model:', model);
            send(model.toJSON()); // it only gets the attributes;
        }
        model.fetch().then(fetchModel, send);
        console.log('end server readModel');
    },
    updateModel: function(req, res, next) {
        var send          = _.bind(res.send, res);
        var hasModelAndId = req.params.model && req.params.id;
        var modelExists   = !!Graft.$models[req.params.model];
        var options       = req.body;

        if (!hasModelAndId || !modelExists) { return next(404); }

        var model = new Graft.$models[req.params.model]({
            id: req.params.id
        });<commit_msg>remove console<commit_after>var express  = require('express');
var http     = require('http');
var path     = require('path');

// This middleware needs to mount routes, so
// it extends the express object.

var _express = express();
this.express = _express;
this.server  = http.createServer(this.express);
_.extend(this, _express);


// Mount all the rest api routes
this.addInitializer(function(opts) {
    debug('Initialize REST api');
    this.post('/api/:model', this.createModel);
    this.get('/api/:model/:id', this.readModel);
    this.put('/api/:model/:id', this.updateModel);
    this.patch('/api/:model/:id', this.updateModel);
    this.del('/api/:model/:id', this.deleteModel);
    this.get('/api/:collection', this.readCollection);
    Graft.reqres.setHandler('model:name', this.modelName);
    Graft.reqres.setHandler('model:load', this.loadModel);
});

Graft.Middleware.on('listen', function(Server) {
    debug('Mounting REST routes');
    Server.use(this);
}, this);

// Implementations for each of the methods
_.extend(this, {
    readModel: function(req, res, next) {
        var send = _.bind(res.send, res);
        var hasModelAndId = req.params.model && req.params.id;
        var modelExists = !!Graft.$models[req.params.model];

        if (!hasModelAndId || !modelExists) { return next(404); }

        var model = new Graft.$models[req.params.model]({
            id: req.params.id
        });

        function fetchModel(attrs) {
            debug('fetching model', req.params.model, req.params.id);
            send(model.toJSON()); // it only gets the attributes;
        }
        model.fetch().then(fetchModel, send);
    },
    updateModel: function(req, res, next) {
        var send          = _.bind(res.send, res);
        var hasModelAndId = req.params.model && req.params.id;
        var modelExists   = !!Graft.$models[req.params.model];
        var options       = req.body;

        if (!hasModelAndId || !modelExists) { return next(404); }

        var model = new Graft.$models[req.params.model]({
            id: req.params.id
        });
{'fraction_non_alphanumeric': 0.15952597994530537, 'fraction_numerical': 0.0027347310847766638, 'mean_word_length': 2.8466257668711656, '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': '7427108', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1334, 'n_words': 292}