Пример #1
0
'use strict';

var a127 = require('a127-magic');
var express = require('express');
var app = express();

a127.init(function(config) {
  app.use(a127.middleware(config));

  app.listen(process.env.PORT || 10010);

  console.log('try this:\nhttp://127.0.0.1:10010/weather?city=Kinston,NC');
});
Пример #2
0
'use strict';

var a127 = require('a127-magic');
var express = require('express');
var app = express();

module.exports = app; // for testing

// initialize a127 framework
a127.init(function(config) {

  // include a127 middleware
  app.use(a127.middleware(config));

  // error handler to emit errors as a json string
  app.use(function(err, req, res, next) {
    if (err && typeof err === 'object') {
      Object.defineProperty(err, 'message', { enumerable: true }); // include message property in response
      res.end(JSON.stringify(err));
    }
    next(err);
  });
  var port = process.env.PORT || 10010;
  // begin listening for client requests
  app.listen(port);

  console.log('try this:\ncurl http://127.0.0.1:' + port + '/movies');
});
Пример #3
0
'use strict';

var a127 = require('a127-magic');
var express = require('express');
var app = express();
var info = require('./config');
var volos = info.volos;

module.exports = app; // for testing

a127.init(function(config) {
  app.use(a127.middleware(config));
  app.listen(process.env.PORT || 10010);
  createApp(config, function(err, app) {
    console.log('try this:\ncurl \'http://127.0.0.1:10010/hello?name=Scott&apiKey='+app.credentials[0].key + "\'");
  });
});

// Use Volos.js management API to create developer and app on Apigee Edge. 
function createApp(config, cb) {

  config.user = config.username; // Management.create expects 'user' parameter in config obj

  var management = volos.Management.create(config);

  management.deleteDeveloper(info.devRequest.email, function() {

    console.log('Creating developer %s', info.devRequest.email);

    management.createDeveloper(info.devRequest , function(err, developer) {
      if (err) { throw err; }
Пример #4
0
'use strict';

var a127 = require('a127-magic');
var express = require('express');
var app = express();

module.exports = app; // for testing

a127.init(function(config) {

  app.use(a127.middleware(config));

  app.listen(process.env.PORT || 10010);

  console.log('try this:\ncurl http://127.0.0.1:10010/hello?name=Scott');
});
Пример #5
0
a127.init(function (swaggerConfig) {
  app.use(morgan('dev'));
  app.use(bodyParser.json());
  //app.use(errors.middleware.crashProtector());

  // central point for all authentication
  auth.auth(app, config, auth.requireAuth);

  /**
   * Serenity-datasource module standard configuration
   * This configuration is defined in global application configuration
   * which is exposed node config module
   * For more information about serenity-datasource module configuration
   * see module documentation
   */
    // @TODO add try/catch logic
  datasource.init(config);
  partialResponseHelper = new ResponseHelper(datasource);
  app.use(partialResponseHelper.parseFields);

  // a127 middlewares
  app.use(a127.middleware(swaggerConfig));

  // Serve the Swagger documents and Swagger UI
  if (config.has('app.loadDoc') && config.get('app.loadDoc')) {
    // adding ui options
    var swaggerTools = swaggerConfig['a127.magic'].swaggerTools;
    app.use(swaggerTools.swaggerUi({
      swaggerUi: config.ui.swaggerUi,
      apiDocs: config.ui.apiDocs
    }));
  }

  // Add logging
  app.use(function(err, req, res, next) {
    if (err) {
      winston.error(err.stack || JSON.stringify(err));
      routeHelper.middleware.errorHandler(err, req, res, next);
    } else {
      next();
    }
  });

  // render response data as JSON
  app.use(routeHelper.middleware.renderJson);

  var port;
  if (config.has('app.port')) {
    port = config.get('app.port');
  } else {
    port = 10010;
  }

  app.listen(port);

  winston.info('Express server listening on port ' + port);
});
Пример #6
0
Файл: app.js Проект: colatoh/hw3
'use strict';

var a127 = require('a127-magic');
var express = require('express');
var app = express();

module.exports = app; // for testing

// initialize a127 framework
a127.init(function(config) {

  // include a127 middleware
  app.use(a127.middleware(config));

  // error handler to emit errors as a json string
  app.use(function(err, req, res, next) {
    if (err && typeof err === 'object') {
      res.end(JSON.stringify(err));
    }
    next(err);
  });

  // begin listening for client requests
  app.listen(process.env.PORT || 10010);

  console.log('try this:\ncurl http://127.0.0.1:10010/hello?name=Scott');
});
Пример #7
0
'use strict';

var a127 = require('a127-magic');
var express = require('express');
var app = express();

// uncomment the following if you need to parse incoming form data
//app.use(express.bodyParser());

a127.init(function(config) {
  app.use(a127.middleware(config));

  app.listen(process.env.PORT || 10010);

});

Пример #8
0
'use strict';

var a127 = require('a127-magic');
var express = require('express');
var app = express();

module.exports = app; // for testing

// initialize a127 framework
a127.init(function(config) {

  // include a127 middleware
  app.use(a127.middleware(config));

  // error handler to emit errors as a json string
  app.use(function(err, req, res, next) {
    if (err && typeof err === 'object') {
      Object.defineProperty(err, 'message', { enumerable: true });
      return res.end(JSON.stringify(err));
    }
    next(err);
  });

  // begin listening for client requests
  var port = process.env.PORT || 10010;
  app.listen(port);

  console.log('proxy started on port %d', port);
});