<commit_before>var mkdirp = require('mkdirp');
var path = require('path');
var serveStatic = require('serve-static');

module.exports = function (reporter, definition) {
  if (!reporter.express) {
    throw new Error('static-resources depends on express extension and requires http server to run. ');
  }

  var staticResourcesPath;

  if (definition.options.directory) {
    staticResourcesPath = definition.options.directory;
  } else {
    staticResourcesPath = path.join(reporter.options.dataDirectory, 'staticResources');
  }

  mkdirp.sync(staticResourcesPath);

  reporter.on('express-configure', function (app) {
    app.use('/static-resources', serveStatic(staticResourcesPath));
  });

  function resolveStaticResourcesPath (req) {
    var escapedUrl = req.url.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
    var path = (req.originalUrl || '/').replace(new RegExp(escapedUrl + '$'), '');
    var base = req.protocol + '://' + req.get('host') + path;
    return base + '/static-resources';
  }

  reporter.beforeRenderListeners.insert({after: 'data', before: 'scripts'}, definition.name, function (req, res) {
    req.data = req.data || {};
    req.data['$staticResources'] = resolveStaticResourcesPath(req);
  });
};
<commit_msg>only log warning when we aren't able to resolve $staticResources jsreport/jsreport#167<commit_after>var mkdirp = require('mkdirp');
var path = require('path');
var serveStatic = require('serve-static');

module.exports = function (reporter, definition) {
  if (!reporter.express) {
    throw new Error('static-resources depends on express extension and requires http server to run. ');
  }

  var staticResourcesPath;

  if (definition.options.directory) {
    staticResourcesPath = definition.options.directory;
  } else {
    staticResourcesPath = path.join(reporter.options.dataDirectory, 'staticResources');
  }

  mkdirp.sync(staticResourcesPath);

  reporter.on('express-configure', function (app) {
    app.use('/static-resources', serveStatic(staticResourcesPath));
  });

  function resolveStaticResourcesPath (req) {
    if (!req.url) {
      reporter.logger.warn('Unable to resolve path to static resources. ');
      return null;
    }
    var escapedUrl = req.url.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
    var path = (req.originalUrl || '/').replace(new RegExp(escapedUrl + '$'), '');
    var base = req.protocol + '://' + req.get('host') + path;
    return base + '/static-resources';
  }

  reporter.beforeRenderListeners.insert({after: 'data', before: 'scripts'}, definition.name, function (req, res) {
    req.data = req.data || {};
    req.data['$staticResources'] = resolveStaticResourcesPath(req);
  });
};

{'fraction_non_alphanumeric': 0.17767062314540058, 'fraction_numerical': 0.001112759643916914, 'mean_word_length': 3.9944444444444445, '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': '2812274', 'n_tokens_mistral': 816, 'n_tokens_neox': 799, 'n_words': 171}