<commit_before>'use strict';

let http = require('http');
let https = require('https');
let path = require('path');
const bodyParser = require('body-parser');
const BaseFrameworkStrategy = require('../BaseFrameworkStrategy/BaseFrameworkStrategy');

class ExpressFrameworkStrategy extends BaseFrameworkStrategy {
  
  constructor(config) {
    super(Object.assign({}, {
      type: BaseFrameworkStrategy.constants.EXPRESS
    }, config));
    this.framework = require(BaseFrameworkStrategy.constants.EXPRESS);
    this.app = this.framework();
    return this;
  }

  forceSecure(req, res, next) {
    if (req.secure || req.headers['x-forwarded-proto'] === 'https') {
      return next(); 
    } 
    res.redirect('https://' + req.hostname + ':' + this.config.https.port + req.url);
  }

  start() {

    let me = this;
    let superStart = super.start.bind(me);
    let port = (me.config.http && me.config.http.port) || 
      BaseFrameworkStrategy.constants.DEFAULT_PORT;

    me.app.use(bodyParser.json());
    if (me.forceHttps) {
      me.app.use(me.forceSecure.bind(me));
    }

    return new Promise(resolve => {

      me.server = http
        .createServer(me.app)
        .listen(port, () => {

          if (me.config.https && me.config.https.port) {

            me.httpsServer = https
              .createServer(me.config.https.options, me.app)
              .listen(me.config.https.port, () => {
                superStart();
                resolve(me);
              });

          } else {
            superStart(); 
            resolve(me); <commit_msg>add ability to serve static files from express<commit_after>'use strict';

let http = require('http');
let https = require('https');
let path = require('path');
const bodyParser = require('body-parser');
const BaseFrameworkStrategy = require('../BaseFrameworkStrategy/BaseFrameworkStrategy');

class ExpressFrameworkStrategy extends BaseFrameworkStrategy {
  
  constructor(config) {
    super(Object.assign({}, {
      type: BaseFrameworkStrategy.constants.EXPRESS
    }, config));
    this.framework = require(BaseFrameworkStrategy.constants.EXPRESS);
    this.app = this.framework();
    return this;
  }

  forceSecure(req, res, next) {
    if (req.secure || req.headers['x-forwarded-proto'] === 'https') {
      return next(); 
    } 
    res.redirect('https://' + req.hostname + ':' + this.config.https.port + req.url);
  }

  start() {

    let me = this;
    let superStart = super.start.bind(me);
    let port = (me.config.http && me.config.http.port) || 
      BaseFrameworkStrategy.constants.DEFAULT_PORT;

    if (me.config.serveStatic) {
      me.app.use(me.framework.static(me.config.serveStatic));
    }

    me.app.use(bodyParser.json());
    if (me.forceHttps) {
      me.app.use(me.forceSecure.bind(me));
    }

    return new Promise(resolve => {

      me.server = http
        .createServer(me.app)
        .listen(port, () => {

          if (me.config.https && me.config.https.port) {

            me.httpsServer = https
              .createServer(me.config.https.options, me.app)
              .listen(me.config.https.port, () => {
                superStart();
                resolve(me);
              });

          } else {
            superStart(); 
            resolve(me); 
{'fraction_non_alphanumeric': 0.1504424778761062, 'fraction_numerical': 0.0, 'mean_word_length': 2.4872340425531916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '2769902', 'n_tokens_mistral': 986, 'n_tokens_neox': 962, 'n_words': 172}