<commit_before>'use strict';

const express = require('express');
const restify = require('express-restify-mongoose');
const receiveMessageRoute = require('./receive-message');
const sendMessageRoute = require('./send-message');
const importMessageRoute = require('./import-message');

// middleware
const authenticateMiddleware = require('../../lib/middleware/authenticate');

const router = express.Router();

const ConversationModel = require('../models/Conversation');
const MessageModel = require('../models/Message');
const CampaignModel = require('../models/Campaign');

restify.serve(router, ConversationModel, { name: 'conversations' });
restify.serve(router, MessageModel, { name: 'messages' });
restify.serve(router, CampaignModel, { name: 'campaigns' });

module.exports = function init(app) {
  app.get('/', (req, res) => {
    res.send('hi');
  });
  // TODO: Eventually remove this.
  // @see https://github.com/DoSomething/gambit-conversations/issues/55
  app.use((req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
    return next();
  });
  app.use(router);
  app.use('/api/v1/receive-message',
    authenticateMiddleware(),
    receiveMessageRoute);
  app.use('/api/v1/send-message',
    authenticateMiddleware(),
    sendMessageRoute);
  app.use('/api/v1/import-message',
    authenticateMiddleware(),
    importMessageRoute);
};<commit_msg>added parseMetadataMiddleware to routes/index.js<commit_after>'use strict';

const express = require('express');
const restify = require('express-restify-mongoose');
const receiveMessageRoute = require('./receive-message');
const sendMessageRoute = require('./send-message');
const importMessageRoute = require('./import-message');

// middleware
const authenticateMiddleware = require('../../lib/middleware/authenticate');
const parseMetadataMiddleware = require('../../lib/middleware/metadata-parse');

const router = express.Router();

const ConversationModel = require('../models/Conversation');
const MessageModel = require('../models/Message');
const CampaignModel = require('../models/Campaign');

restify.serve(router, ConversationModel, { name: 'conversations' });
restify.serve(router, MessageModel, { name: 'messages' });
restify.serve(router, CampaignModel, { name: 'campaigns' });

module.exports = function init(app) {
  app.get('/', (req, res) => {
    res.send('hi');
  });
  // TODO: Eventually remove this.
  // @see https://github.com/DoSomething/gambit-conversations/issues/55
  app.use((req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
    return next();
  });
  // restified routes
  app.use(router);
  // authenticate all requests after this line
  app.use(authenticateMiddleware());
  // parse metadata like requestId and retryCount for all requests after this line
  app.use(parseMetadataMiddleware());
  // receive-message route
  app.use('/api/v1/receive-message',
    receiveMessageRoute);
  // send-message route
  app.use('/api/v1/send-message',
    sendMessageRoute);
  // import-message route
  app.use('/api/v1/import-message',
    importMessageRoute);
};
{'fraction_non_alphanumeric': 0.17289577635976908, 'fraction_numerical': 0.003038590094196293, 'mean_word_length': 4.666092943201377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1413680', 'n_tokens_mistral': 965, 'n_tokens_neox': 956, 'n_words': 189}