<commit_before>var Statique = require("statique")
  , Events = require("events")
  , EventEmitter = Events.EventEmitter
  , Http = require("http")
  , Url = require("url")
  , QueryString = require("querystring")
  , LienCreator = require("./creator")
  ;

var Lien = module.exports = function (opt_options) {

    var self = new EventEmitter();
    self.routes = {};

    self._sServer = new Statique({
        root: opt_options.root || (__dirname + "/public")
      , cache: opt_options.cache
    }).setRoutes(self.routes);

    self._server = Http.createServer(function (request, response) {
        if (self._sServer.exists(request, response)) {
            self._sServer.serve(request, response);
        } else {
            self.emit("request", LienCreator.call(self, req, res));
        }
    });

    self._server.listen(opt_options.port, opt_options.host);

    /*!
     * Methods
     * */
    self.page = {};
    self.page.add = function (route, method, callback) {

        var sRoute = {};

        if (typeof method === "function") {
            callback = method;
            method = undefined;
        }

        function generateCallback() {
            return function (req, res, form) {
                var lien = LienCreator.call(self, req, res);
                if (req.method.toLowerCase() === "post") {
                    return form.on("done", function (form) {
                        if (form.error) {
                            return lien.end(form.error, 500);
                        }
                        if (form.data) {
                            try {
                                form.data = JSON.parse(form.data);
                            } catch (e) {
                                form.data = QueryString.parse(form.data);
                            }
                        }

                        lien.data = form.data;
                        callback.call(self, lien);
                    });
                }
                callback.call(self, lien);
            }
        }

        if (route.constructor.name === "RegExp") {

            sRoute.regexp = route;
            sRoute.type = "regexp";

            if (!method) {
                sRoute.handler = generateCallback();
            } else {
                sRoute.url = {};
                sRoute.url[method] = generateCallback();
            }

            self._sServer._regexpRoutes.push(sRoute);
            return;
        } else if (typeof route === "string") {
            // TODO
            // var oldRoute = self._sServer.getRoute(route);
            // // TODO Handle met
            // if (oldRoute.url) {
            // }
            // sRoute.url =
        }

        if (!method) {
            sRoute = method;
        } else {
            method = method.toLowerCase();
            sRoute[method] = generateCallback();
        }

        self._sServer._routes[route] = sRoute;
    };

    self.page.delete = function (route, method) {
        if (arguments.length < 2) {
            if (self.routes[route]) {
                delete self.routes[route];
            }
        } else {
            if (self.routes[route] && self.routes[route][method]) {
                delete self.routes[route][method];
            }
        }
    };

    return self;
};
<commit_msg>Added a hack to support string routes<commit_after>var Statique = require("statique")
  , Events = require("events")
  , EventEmitter = Events.EventEmitter
  , Http = require("http")
  , Url = require("url")
  , QueryString = require("querystring")
  , LienCreator = require("./creator")
  ;

var Lien = module.exports = function (opt_options) {

    var self = new EventEmitter();
    self.routes = {};

    self._sServer = new Statique({
        root: opt_options.root || (__dirname + "/public")
      , cache: opt_options.cache
    }).setRoutes(self.routes);

    self._server = Http.createServer(function (request, response) {
        if (self._sServer.exists(request, response)) {
            self._sServer.serve(request, response);
        } else {
            self.emit("request", LienCreator.call(self, req, res));
        }
    });

    self._server.listen(opt_options.port, opt_options.host);

    /*!
     * Methods
     * */
    self.page = {};
    self.page.add = function (route, method, callback) {

        var sRoute = {};

        if (typeof method === "function") {
            callback = method;
            method = undefined;
        }

        function generateCallback() {
            return function (req, res, form) {
                var lien = LienCreator.call(self, req, res);
                if (req.method.toLowerCase() === "post") {
                    return form.on("done", function (form) {
                        if (form.error) {
                            return lien.end(form.error, 500);
                        }
                        if (form.data) {
                            try {
                                form.data = JSON.parse(form.data);
                            } catch (e) {
                                form.data = QueryString.parse(form.data);
                            }
                        }

                        lien.data = form.data;
                        callback.call(self, lien);
                    });
                }
                callback.call(self, lien);
            }
        }

        // TODO
        if (typeof route === "string") {
            route = new RegExp(route);
        }

        if (route.constructor.name === "RegExp") {

            sRoute.regexp = route;
            sRoute.type = "regexp";

            if (!method) {
                sRoute.handler = generateCallback();
            } else {
                sRoute.url = {};
                sRoute.url[method] = generateCallback();
            }

            self._sServer._regexpRoutes.push(sRoute);
            return;
        }

        if (!method) {
            sRoute = method;
        } else {
            method = method.toLowerCase();
            sRoute[method] = generateCallback();
        }

        self._sServer._routes[route] = sRoute;
    };

    self.page.delete = function (route, method) {
        if (arguments.length < 2) {
            if (self.routes[route]) {
                delete self.routes[route];
            }
        } else {
            if (self.routes[route] && self.routes[route][method]) {
                delete self.routes[route][method];
            }
        }
    };

    return self;
};

{'fraction_non_alphanumeric': 0.12715252152521525, 'fraction_numerical': 0.0012300123001230013, 'mean_word_length': 1.308374733853797, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1717827', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1716, 'n_words': 337}