module.exports = function(server) {
  var restApiRoot = server.get('restApiRoot');

  var explorerApp = explorer(server, { basePath: restApiRoot });
  server.use('/explorer', explorerApp);
  server.once('started', function() {
    var baseUrl = server.get('url').replace(/\/$/, '');
    console.log('Browse your REST API at %s%s', baseUrl, explorerApp.mountpath);
  });
};
Beispiel #2
0
module.exports = function(loopback, app){
    var explorer = require('loopback-explorer');
    app.use('/explorer', explorer(app));
}
Beispiel #3
0
app.use(loopback.bodyParser());
app.use(loopback.methodOverride());

// Establish our overly-permissive CORS rules.
app.use(cors());

var apiPath = '/api';

// Expose a rest api
app.use(apiPath, loopback.rest());

// API explorer (if present)
var explorerPath = '/explorer';
try {
  var explorer = require('loopback-explorer');
  app.use(explorerPath, explorer(app, { basePath: apiPath }));
} catch(e){
  // ignore errors, explorer stays disabled
}


// Let express routes handle requests that were not handled
// by any of the middleware registered above.
// This way LoopBack REST and API Explorer take precedence over
// express routes.
app.use(app.router);

// The static file server should come after all other routes
// Every request that goes through the static middleware hits
// the file system to check if a file exists.
app.use(loopback.static(path.join(__dirname, 'public')));
Beispiel #4
0
var loopback = require('loopback');
var app = loopback();
var explorer = require('loopback-explorer');

app.use('/api', loopback.rest());
app.use('/explorer', explorer(app, { basePath: '/api' }));

app.listen(3000);
var db = loopback.createDataSource({
  connector: require('loopback-connector-mongodb'),
  database: 'todo-example'
});

// models
var User = require('models/user');
var Todo = require('models/todo');

// setup the model data sources
User.attachTo(db);
Todo.attachTo(db);
server.model(User);
server.model(Todo);

// TODO(ritch) this should be unecessary soon....
server.model(Todo.getChangeModel());

// root api path
var apiPath = CONFIG.api.root;

// enable authentication
// server.enableAuth();

// middleware
server.use(loopback.logger('dev'));
server.use(loopback.token());
server.use(apiPath, loopback.rest());
server.use('/explorer', explorer(server, {basePath: apiPath}));

Beispiel #6
0
  app.get('/feature-flags', function(req, res) {
    res.json(features);
  });

  // example feature, "--feature crash" enables a /crash handler
  if (app.enabled('feature:crash')) {
    app.use('/crash', function(_req, _res) {
      process.exit(1);
    });
  }
};

try {
  // API explorer
  var explorer = require('loopback-explorer');
  app.use('/explorer/workspace', explorer(workspace,
    { basePath: '/workspace/api' }));
  app.use('/explorer/arc-api', explorer(arcApi, { basePath: '/api' }));
} catch(err) {
  // silently ignore the error, the explorer is not available in "production"
}

// static files
app.use(require('express-jsxtransform')())
   .use(express.static(path.join(__dirname, '../client/www')));

var listen = app.listen;
app.listen = function() {
  var server = process.server = listen.apply(app, arguments);
  meshProxy.setupPrimus(server);
  devtools.setupWebSocketServer(server);
  pm.start();