<commit_before>"use strict";

var P = require('bluebird');
var fs = P.promisifyAll(require('fs'));
var path = require('path');
// swagger-ui helpfully exports the absolute path of its dist directory
var docRoot = require('swagger-ui').dist + '/';

function staticServe (restbase, req) {
    // Expand any relative paths for security
    var filePath = req.query.path.replace(/\.\.\//g, '');
    return fs.readFileAsync(docRoot + filePath, 'utf8')
    .then(function(body) {
        if (filePath === '/index.html') {
            // Rewrite the HTML to use a query string
            body = body.replace(/((?:src|href)=['"])/g, '$1?doc=&path=')
                // Some self-promotion
                .replace(/<a id="logo".*?<\/a>/,
                        '<a id="logo" href="http://restbase.org">RESTBase</a>')
                .replace(/<title>[^<]*<\/title>/,
                        '<title>RESTBase docs</title>')
                // Replace the default url with ours, switch off validation &
                // limit the size of documents to apply syntax highlighting to
                .replace(/url: url,/, 'url: "?spec", validatorUrl: null, highlightSizeThreshold: 10000,');
        }

        var contentType = 'text/html';
        if (/\.js$/.test(filePath)) {
            contentType = 'text/javascript';
        } else if (/\.png/.test(filePath)) {
            contentType = 'image/png';
        } else if (/\.css/.test(filePath)) {
            contentType = 'text/css';
            body = body.replace(/\.\.\/(images|fonts)\//g, '?doc&path=$1/');
        }
        return P.resolve({
            status: 200,
            headers: {
                'content-type': contentType,<commit_msg>Expand operation list by default<commit_after>"use strict";

var P = require('bluebird');
var fs = P.promisifyAll(require('fs'));
var path = require('path');
// swagger-ui helpfully exports the absolute path of its dist directory
var docRoot = require('swagger-ui').dist + '/';

function staticServe (restbase, req) {
    // Expand any relative paths for security
    var filePath = req.query.path.replace(/\.\.\//g, '');
    return fs.readFileAsync(docRoot + filePath, 'utf8')
    .then(function(body) {
        if (filePath === '/index.html') {
            // Rewrite the HTML to use a query string
            body = body.replace(/((?:src|href)=['"])/g, '$1?doc=&path=')
                // Some self-promotion
                .replace(/<a id="logo".*?<\/a>/,
                        '<a id="logo" href="http://restbase.org">RESTBase</a>')
                .replace(/<title>[^<]*<\/title>/,
                        '<title>RESTBase docs</title>')
                // Replace the default url with ours, switch off validation &
                // limit the size of documents to apply syntax highlighting to
                .replace(/sorter *: "alpha"/, 'sorter: "alpha", url: "?spec", validatorUrl: null, highlightSizeThreshold: 10000, docExpansion: "list",');
        }

        var contentType = 'text/html';
        if (/\.js$/.test(filePath)) {
            contentType = 'text/javascript';
        } else if (/\.png/.test(filePath)) {
            contentType = 'image/png';
        } else if (/\.css/.test(filePath)) {
            contentType = 'text/css';
            body = body.replace(/\.\.\/(images|fonts)\//g, '?doc&path=$1/');
        }
        return P.resolve({
            status: 200,
            headers: {
                'content-type': contentType,
{'fraction_non_alphanumeric': 0.17378752886836027, 'fraction_numerical': 0.006351039260969977, 'mean_word_length': 1.9615384615384615, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, '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': '6369499', 'n_tokens_mistral': 1048, 'n_tokens_neox': 995, 'n_words': 247}