<commit_before>const http = require('http');
const url = require('url');
const fs = require('fs');
const path = require('path');
const colors = require('colors');
const qs = require('querystring');
const objExtend = require('extend');
const glob = require('glob');
const request = require('superagent');
const Freemarker = require('freemarker.js');

const readstatic = require('./lib/readstatic');
const rootPath = process.cwd();
const configPath = path.join(rootPath, 'fsconfig.json');

const port = process.env.PORT || 9090;

const defaultCfg = {
    ftlRoot: 'ftl',
    cmsDomain: '',
    static: 'static|build|dist|mock',
    route: {},
    globalData: {}
};

const bodyParse = function(req, fn){
    let arr = [];
    req.on('data', function(data){
        arr.push(data);
    });
    req.on('end', function(){
        let data = Buffer.concat(arr).toString(),ret;
        try{
            ret = qs.parse(data);
        }catch(err){
            ret = {
                code: 500,
                msg: 'post data error'
            }
        }
        fn && fn(ret);
    });
};

const handleProxy = function(method, url, req, res, postData){
    const headers = req['headers'];
    let proxy = request[method](url).set({
        'User-Agent': headers['user-agent'],
        'Content-Type': headers['content-type'] || '',
        'Cookie': headers['cookie'] || '',
        'Accept': headers['accept'] || '',
    });

    if(method == 'post'){
        proxy = proxy.send(postData || {})
    }

    proxy.end((err, resp) => {
        res.writeHead(resp.status, resp.headers);<commit_msg>:ambulance: 修复数据类型为 formData 或 json 时，请求数据被解析<commit_after>const http = require('http');
const url = require('url');
const fs = require('fs');
const path = require('path');
const colors = require('colors');
const qs = require('querystring');
const objExtend = require('extend');
const glob = require('glob');
const request = require('superagent');
const Freemarker = require('freemarker.js');

const readstatic = require('./lib/readstatic');
const rootPath = process.cwd();
const configPath = path.join(rootPath, 'fsconfig.json');

const port = process.env.PORT || 9090;

const defaultCfg = {
    ftlRoot: 'ftl',
    cmsDomain: '',
    static: 'static|build|dist|mock',
    route: {},
    globalData: {}
};

const bodyParse = function(req, fn){
    let arr = [];
    req.on('data', function(data){
        arr.push(data);
    });
    req.on('end', function(){
        const bufferArr = Buffer.concat(arr);
        let data = bufferArr.toString(),
            ret;
        const contentType = req['headers']['content-type'];
        try {
            if (contentType.indexOf('multipart/form-data') > -1) {
                ret = bufferArr;
            } else if (contentType.indexOf('application/json') > -1) {
                ret = data;
            } else {
                ret = qs.parse(data);
            }
        }catch(err){
            ret = {
                code: 500,
                msg: 'post data error'
            }
        }
        fn && fn(ret);
    });
};

const handleProxy = function(method, url, req, res, postData){
    const headers = req['headers'];
    let proxy = request[method](url).set({
        'User-Agent': headers['user-agent'],
        'Content-Type': headers['content-type'] || '',
        'Cookie': headers['cookie'] || '',
        'Accept': headers['accept'] || '',
    });

    if(method == 'post'){
        proxy = proxy.send(postData || {})
    }

    proxy.end((err, resp) => {
        res.writeHead(resp.status, resp.headers);
{'fraction_non_alphanumeric': 0.17795895417486646, 'fraction_numerical': 0.004498172617374192, 'mean_word_length': 2.572289156626506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1473387', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1065, 'n_words': 241}