Exemplo n.º 1
0
"use strict";


var express = require("express"),
  grace = require("grace"),
  http = require('http'),
  request = require('request'),
  port = process.env.PORT || 5001,
  apiKey = process.env.ECHONEST_API_KEY,
  profileUrl = "http://developer.echonest.com/api/v4/track/profile?bucket=audio_summary&api_key=" + apiKey,
  app = grace.create();

function setCors(req, res) {
  var origin = req.header('origin');

  if (origin && origin.match(/(localhost|\.dev|\.local|127\.0\.0\.1):\d+$/)) {
    origin = req.headers.origin;
  } else {
    origin = "http://djgif.com";
  }

  res.setHeader("Access-Control-Allow-Origin", origin);
  res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,Content-Type");
}

app.on("error", function (error) {
  console.log("ERROR CAUGHT")
//  console.error(error);
});

app.on("start", function () {
Exemplo n.º 2
0
    log4js.setGlobalLogLevel(process.env.LOG_LEVEL);
}
var logger = log4js.getLogger('server.js');

var grace = require('grace');
var express = require('express'), app = express();
var notification = require('./controllers/notification');
var errorReporter = require('./util/error-reporter');
var errorUtils = require('./util/error-utils.js');
var getFullError = errorUtils.getFullError;
var when = require('when');
var auth = require('./middlewares/auth');

var PORT = 8080;

var graceApp = grace.create();

exitOnSignal('SIGINT');
exitOnSignal('SIGTERM');

function exitOnSignal(signal) {
    process.on(signal, function() {
        logger.debug('Caught ' + signal + ', exiting');
        graceApp.shutdown(0);
    });
}

app.use(auth.authorise);
app.use(require('./controllers'));
app.use(auth.errorHandler);
app.use(defaultErrorHandler);