<commit_before>'use strict';

var root = __dirname;

var http = require('http');
var fs = require('fs');
var fileserver = require('./app/fileserver.js');
var fileuploader = require('./app/fileuploader.js');

var server = http.createServer(function (req, res) {
    switch (req.method) {
        case 'GET':
            fileserver.streamFile(req, res, root);
            break;
        case 'POST':
            fileuploader.upload(req, res, function(fields, files) {
                res.setHeader('Content-Type', 'application/json; charset="utf-8"');
                if (files.file.size > 0) {
                    if (fields.name !== undefined && fields.name !== '') {
                        var extension = files.file.name.match(/.*\.(.*)$/);
                        files.file.name = fields.name + '.' + extension[1];
                    }
                    var publicPath = '/upload/' + files.file.name;
                    var newPath = root + '/public' + publicPath;
                    // move file to a new path
                    fs.rename(files.file.path, newPath);
                    // return file info as a response
                    files.file.path = publicPath;
                    res.end(JSON.stringify(files.file));
                } else {
                    res.end(JSON.stringify({
                        path: null
                    }));
                }
            });
            break;
    }

}).listen(3000, '127.0.0.1');

console.log('Server running at http://127.0.0.1:3000/');<commit_msg>feat: add server port configuration #7<commit_after>'use strict';

var root = __dirname;
var port = (process.env.USER == 'root' ? 80 : 3000);

var http = require('http');
var fs = require('fs');
var fileserver = require('./app/fileserver.js');
var fileuploader = require('./app/fileuploader.js');

var server = http.createServer(function (req, res) {
    switch (req.method) {
        case 'GET':
            fileserver.streamFile(req, res, root);
            break;
        case 'POST':
            fileuploader.upload(req, res, function(fields, files) {
                res.setHeader('Content-Type', 'application/json; charset="utf-8"');
                if (files.file.size > 0) {
                    if (fields.name !== undefined && fields.name !== '') {
                        var extension = files.file.name.match(/.*\.(.*)$/);
                        files.file.name = fields.name + '.' + extension[1];
                    }
                    var publicPath = '/upload/' + files.file.name;
                    var newPath = root + '/public' + publicPath;
                    // move file to a new path
                    fs.rename(files.file.path, newPath);
                    // return file info as a response
                    files.file.path = publicPath;
                    res.end(JSON.stringify(files.file));
                } else {
                    res.end(JSON.stringify({
                        path: null
                    }));
                }
            });
            break;
    }

}).listen(port);

console.log('Server running at http://127.0.0.1:' + port + '/');
{'fraction_non_alphanumeric': 0.1463726430169383, 'fraction_numerical': 0.012464046021093002, 'mean_word_length': 1.4414976599063962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '2660711', 'n_tokens_mistral': 880, 'n_tokens_neox': 819, 'n_words': 188}