<commit_before>/*
 Copyright 2017 <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

'use strict';

const express = require('express');
const socketIo = require('socket.io');
const path = require('path');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const compression = require('compression');
const { dbConfig, appConfig } = require('./config/defaults/config');
const dbRoom = require('./db/connectors/room');
const positionManager = require('./managers/positions');
const { version: appVersion, name: appName } = require('./package');

const app = express();
const io = socketIo();

console.log(`Running version ${appVersion} of ${appName}.`);

app.io = io;

app.disable('x-powered-by');

// view engine setup
app.set('views', path.join(appConfig.publicBase, appConfig.viewsPath));
app.set('view engine', 'html');
// eslint-disable-next-line no-underscore-dangle, import/newline-after-import
app.engine('html', require('hbs').__express);
app.use(bodyParser.json());
app.use(compression());
// Logging
app.use(morgan(appConfig.logLevel));

// Serve files from public path
app.use(express.static(appConfig.publicBase));

appConfig.routes.forEach((route) => {
  // eslint-disable-next-line global-require, import/no-dynamic-require
  app.use(route.sitePath, require(path.resolve(route.filePath))(app.io));
});

if (!appConfig.jsonKey) {
  console.log('WARNING! JSONKEY is not set in the config. User authentication will not work.');
}

if (appConfig.mode !== appConfig.Modes.TEST) {
  dbRoom.populateDbRooms({ rooms: dbConfig.rooms });
}

if (!appConfig.disablePositionImport) {
  // TODO Send positions to clients
  positionManager.getAndStoreGooglePositions({
    callback: ({ error, data }) => {
      if (error) {
        console.log('Failed to retrieve Google Maps positions');

        return;
      }

      console.log(`Retrieved and saved ${data.positions.length + 1} positions from Google Maps`);
    },
  });
}

/*
 * Catches all exceptions.
 */
process.on('uncaughtException', (err) => {
  console.error('Caught exception', err);
  console.error(err.stack);
});

module.exports = app;<commit_msg>Update Google positions once per hour.<commit_after>/*
 Copyright 2017 <NAME>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

'use strict';

const express = require('express');
const socketIo = require('socket.io');
const path = require('path');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const compression = require('compression');
const { dbConfig, appConfig } = require('./config/defaults/config');
const dbRoom = require('./db/connectors/room');
const positionManager = require('./managers/positions');
const { version: appVersion, name: appName } = require('./package');

const app = express();
const io = socketIo();

console.log(`Running version ${appVersion} of ${appName}.`);

app.io = io;

app.disable('x-powered-by');

// view engine setup
app.set('views', path.join(appConfig.publicBase, appConfig.viewsPath));
app.set('view engine', 'html');
// eslint-disable-next-line no-underscore-dangle, import/newline-after-import
app.engine('html', require('hbs').__express);
app.use(bodyParser.json());
app.use(compression());
// Logging
app.use(morgan(appConfig.logLevel));

// Serve files from public path
app.use(express.static(appConfig.publicBase));

appConfig.routes.forEach((route) => {
  // eslint-disable-next-line global-require, import/no-dynamic-require
  app.use(route.sitePath, require(path.resolve(route.filePath))(app.io));
});

if (!appConfig.jsonKey) {
  console.log('WARNING! JSONKEY is not set in the config. User authentication will not work.');
}

if (appConfig.mode !== appConfig.Modes.TEST) {
  dbRoom.populateDbRooms({ rooms: dbConfig.rooms });
}

if (!appConfig.disablePositionImport) {
  setInterval(() => {
    // TODO Send positions to clients
    positionManager.getAndStoreGooglePositions({
      io,
      callback: ({ error, data }) => {
        if (error) {
          console.log('Failed to retrieve Google Maps positions');

          return;
        }

        console.log(`Retrieved and saved ${data.positions.length + 1} positions from Google Maps`);
      },
    });
  }, 3600000);
}

/*
 * Catches all exceptions.
 */
process.on('uncaughtException', (err) => {
  console.error('Caught exception', err);
  console.error(err.stack);
});

module.exports = app;
{'fraction_non_alphanumeric': 0.1446188340807175, 'fraction_numerical': 0.004671150971599402, 'mean_word_length': 4.4235055724417425, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2568758', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1525, 'n_words': 453}