<commit_before>var express = require('express');
var bodyParser = require('body-parser');
var passport = require('passport');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

require('./models/db');
require('./config/passport');

app.set('port',(process.env.PORT || 3000));
var routeApi = require('./routes/index');

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

app.use(passport.initialize());
app.use('/api',routeApi);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// Catch unauthorized errors
app.use(function (err,req,res,next) {
  if(err.name === 'UnauthorizedError'){
    res.status(401);
    res.json({"message":err.name + ": " + err.message});
  }
});

// error handler<commit_msg>服务器添加auth权限<commit_after>var express = require('express');
var bodyParser = require('body-parser');
var passport = require('passport');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

require('./models/db');
require('./config/passport');

app.set('port',(process.env.PORT || 3000));
var routeApi = require('./routes/index');

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
  next();
});

app.use(passport.initialize());
app.use('/api',routeApi);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// Catch unauthorized errors
app.use(function (err,req,res,next) {
  if(err.name === 'UnauthorizedError'){
    res.status(401);
    res.json({"message":err.name + ": " + err.message});
  }
});

// error handler
{'fraction_non_alphanumeric': 0.20835405271009447, 'fraction_numerical': 0.012928891098955743, 'mean_word_length': 4.988095238095238, 'pattern_counts': {'":': 4, '<': 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': '6235267', 'n_tokens_mistral': 687, 'n_tokens_neox': 664, 'n_words': 130}