How to use baucis - 10 common examples

To help you get started, we’ve selected a few baucis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wprl / baucis-example / app.js View on Github external
mongoose.model('vegetable').create(vegetables, function (error) {
    if (error) throw error;

    // Create the API routes
    baucis.rest('vegetable');

    // Create the app and listen for API requests
    var app = express();
    app.use('/api', baucis());
    app.listen(3333);

    console.log('Server listening on port 3333.');
  });
});
github wprl / baucis-swagger / index.js View on Github external
// __Dependencies__
var baucis = require('baucis');
var deco = require('deco');
var decorators = deco.require(__dirname, [ 'Controller', 'Api' ]).hash;

baucis.Controller.decorators(decorators.Controller);
baucis.Api.decorators(decorators.Api);
github capaj / Moonridge / utils / baucis.js View on Github external
'use strict'
const debug = require('debug')('moonridge:baucis')
const baucis = require('baucis')
require('baucis-swagger')

const mapVerbToOperation = {
  POST: 'create',
  GET: 'read',
  PUT: 'update',
  DELETE: 'remove'
}

baucis.Controller.decorators(function (options, protect) {
  var controller = this
  const model = controller.model()
  const mrOpts = model.moonridgeOpts
  controller.request(function (request, response, next) {
    // expects request.moonridge to be something like {user: {privilege_level: 30}}
    debug(request.method)
    const operation = mapVerbToOperation[request.method]
    let errWhileCheckingPermissions
    try {
      mrOpts.checkPermission(request, operation)
    } catch (err) {
      errWhileCheckingPermissions = err
    }
    debug('errWhileCheckingPermissions ', errWhileCheckingPermissions)
    if (errWhileCheckingPermissions) {
      return response.status(403).send(baucis.Error.Forbidden(`You lack a privilege to ${request.method} ${model.modelName} collection`))
github wprl / baucis-swagger / index.js View on Github external
// __Dependencies__
var baucis = require('baucis');
var deco = require('deco');
var decorators = deco.require(__dirname, [ 'Controller', 'Api' ]).hash;

baucis.Controller.decorators(decorators.Controller);
baucis.Api.decorators(decorators.Api);
github pjmolina / event-backend / test / domain / fixtures / fakeserver.js View on Github external
Object.keys(models.models).forEach(function (key) {
            var item = models.models[key];
            var controller = baucis.rest(item.name, item.model).hints(true).comments(true);
            item.controller = controller;
            fixture.controllers.push(controller);
        });
github wprl / baucis-swagger / test / fixtures / vegetable.js View on Github external
init: function (done) {
    mongoose.connect(config.mongo.url);

    fixture.controller = baucis.rest('vegetable').hints(true).comments(true);
    fixture.controller.generateSwagger();
    fixture.controller.swagger.lambic = 'kriek';

    baucis.rest('fungus').select('-hyphenated-field-name -password');
    baucis.rest('goose');

    app = express();
    app.use('/api', baucis());

    app.use(function (error, request, response, next) {
      if (error) return response.send(500, error.toString());
      next();
    });

    server = app.listen(8012);
    done();
  },
  deinit: function(done) {
github wprl / baucis-swagger / test / fixtures / vegetable.js View on Github external
init: function (done) {
    mongoose.connect(config.mongo.url);

    fixture.controller = baucis.rest('vegetable').hints(true).comments(true);
    fixture.controller.generateSwagger();
    fixture.controller.swagger.lambic = 'kriek';

    baucis.rest('fungus').select('-hyphenated-field-name -password');
    baucis.rest('goose');

    app = express();
    app.use('/api', baucis());

    app.use(function (error, request, response, next) {
      if (error) return response.send(500, error.toString());
      next();
    });

    server = app.listen(8012);
    done();
github wprl / baucis-swagger / test / fixtures / vegetable.js View on Github external
init: function (done) {
    mongoose.connect(config.mongo.url);

    fixture.controller = baucis.rest('vegetable').hints(true).comments(true);
    fixture.controller.generateSwagger();
    fixture.controller.swagger.lambic = 'kriek';

    baucis.rest('fungus').select('-hyphenated-field-name -password');
    baucis.rest('goose');

    app = express();
    app.use('/api', baucis());

    app.use(function (error, request, response, next) {
      if (error) return response.send(500, error.toString());
      next();
    });

    server = app.listen(8012);
    done();
  },
  deinit: function(done) {
github pjmolina / event-backend / app / server.js View on Github external
Object.keys(models.models).forEach(function(key) { 
    var item = models.models[key];
	if(item.hasController) {
		var controller = baucis.rest(item.name, item.model);
		item.controller = controller;
		controllers.push(controller);
	}
});
github capaj / Moonridge / utils / baucis.js View on Github external
request.baucis.incoming(function (ctx, cb) {
      const doc = ctx.doc
      let errWhileCheckingPermissions
      try {
        mrOpts.checkPermission(request, mapVerbToOperation[request.method], doc)
      } catch (err) {
        errWhileCheckingPermissions = err
      }
      if (errWhileCheckingPermissions === undefined) {
        return cb(null, ctx)
      } else {
        return response.status(403).send(baucis.Error.Forbidden(`You lack a privilege to ${request.method} ${model.modelName} collection`))
      }
    })
    request.baucis.outgoing(function (ctx, cb) {

baucis

Build scalable REST APIs using the open source tools and standards you already know.

MIT
Latest version published 1 year ago

Package Health Score

46 / 100
Full package analysis