How to use derby - 10 common examples

To help you get started, we’ve selected a few derby 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 derbyjs / derby-site / src / server / site.js View on Github external
var path = require('path');
var glob = require('glob');
var parseUrl = require('url').parse;
var derby = require('derby');
var express = require('express');
var app = derby.createApp('site', __filename);

app.serverUse(module, './markdown');
app.serverUse(module, 'derby-stylus');

app.loadViews(__dirname + '/../../views/app');
app.loadStyles(__dirname + '/../../styles/app');

// TODO move this view function elsewhere
// check if the link matches the first parts of the page's namespace
// so that we can highlight 'docs' when in any sub page
app.proto.linkMatch = function(url, render) {
  var segments = url.split('/');
  var ns = render.ns.split(':');
  var i = 1;
  for(i; i < segments.length; i++) {
    if(segments[i] !== ns[i-1]) return false;
github azat-co / mongoui / main.js View on Github external
var derby = require('derby');
derby.use(require('./ui'));
derby.use(require('derby-ui-boot'));


var app = derby.createApp(module);



app.ready(function(model) {

  // console.log(app.page)
  // model.on('set','dbName',function(path,object){
  // });
  // model.on('set','collectionBox', function(path,obj){
  //   console.log('$');
  //   app.page.render();
  // });
  // model.on('set','collections',function(path,obj){
  //   console.log('!');
  //   app.page.render();
  // });
github azat-co / mongoui / main.js View on Github external
var derby = require('derby');
derby.use(require('./ui'));
derby.use(require('derby-ui-boot'));


var app = derby.createApp(module);



app.ready(function(model) {

  // console.log(app.page)
  // model.on('set','dbName',function(path,object){
  // });
  // model.on('set','collectionBox', function(path,obj){
  //   console.log('$');
  //   app.page.render();
  // });
  // model.on('set','collections',function(path,obj){
github derbyjs / derby / bin / default-js / lib / server / index.js View on Github external
var redis = require('redis').createClient(process.env.REDIS_PORT, process.env.REDIS_HOST);
  redis.auth(process.env.REDIS_PASSWORD);
} else if (process.env.REDISCLOUD_URL) {
  var redisUrl = require('url').parse(process.env.REDISCLOUD_URL);
  var redis = require('redis').createClient(redisUrl.port, redisUrl.hostname);
  redis.auth(redisUrl.auth.split(":")[1]);
} else {
  var redis = require('redis').createClient();
}
redis.select(process.env.REDIS_DB || 1);
// Get Mongo configuration 
var mongoUrl = process.env.MONGO_URL || process.env.MONGOHQ_URL ||
  'mongodb://localhost:27017/project';

// The store creates models and syncs data
var store = derby.createStore({
  db: liveDbMongo(mongoUrl + '?auto_reconnect', {safe: true})
, redis: redis
});

function createUserId(req, res, next) {
  var model = req.getModel();
  var userId = req.session.userId || (req.session.userId = model.id());
  model.set('_session.userId', userId);
  next();
}

expressApp
  .use(express.favicon())
  // Gzip dynamically
  .use(express.compress())
  // Respond to requests for application script bundles
github lefnire / derby-auth / example / lib / server / serverError.js View on Github external
module.exports = function() {
    var staticPages = derby.createStatic(path.dirname(path.dirname(__dirname)))

    return function(err, req, res, next) {
        if (err == null) return next()

        console.log(err.stack ? err.stack : err)

        // Customize error handling here
        var message = err.message || err.toString()
        var status = parseInt(message)
        status = (status >= 400 && status < 600) ? status : 500

        if (status === 403 || status === 404 || status === 500) {
            staticPages.render('error', res, status.toString(), status)
        } else {
            res.send(status)
        }
github derbyjs / derby-site / src / app / index.js View on Github external
var derby = require('derby');
var markedOptions = require('./../../config/markedOptions');
var path = require('path');
var app = module.exports = derby.createApp('site', __filename);

if (!derby.util.isProduction) global.app = app;

app.serverUse(module, 'derby-markdown', markedOptions);
app.serverUse(module, 'derby-stylus');
app.loadViews(path.join(__dirname, '/../../views/app'));
app.loadStyles(path.join(__dirname, '/../../styles/app'));
app.component(require('../../components/chat'));
app.component(require('../../components/preferences'));
app.component(require('../../components/sidebar'));

app.get('*', function (page, model, params, next) {
  // it`s used to cheat template engine in derby-template examples
  model.set('_session.openBrackets', '{{');
  if (model.get('_session.loggedIn')) {
    var userId = model.get('_session.userId');
github lefnire / derby-auth / example / lib / auth / index.js View on Github external
var derby = require('derby')
    , app = derby.createApp(module)
    , get = app.get

derby.use(require('derby-ui-boot'));
derby.use(require('../../ui'));
derby.use(require('../../../components'));

get('/', function(page, model) {
  model.query('users').withId(model.get('_userId')).subscribe(function(err, user) {
    model.ref('_user', user);
    page.render();
  });
});

app.ready(function(model) {
    // nothing here
});
github triptec / derby-learn-by-example / lib / app / index.js View on Github external
var derby = require('derby')
  , app = derby.createApp(module)
  , get = app.get
  , view = app.view
  , ready = app.ready
  , start = +new Date()

derby.use(require('../../ui'))
derby.use(require('../../components'));

// ROUTES //

get('/', function(page, model, params) {

    model.subscribe('snippster.data', function(err, data){
        if(err)
            throw err;
        model.set('_snippet',{
github alexyoung / nodejsinaction / ch05-server-side-frameworks / example-derby-app / app / index.js View on Github external
const app = module.exports = require('derby').createApp('hello', __filename);
app.loadViews(__dirname);

// Routes render on client as well as server
app.get('/', (page, model) => {
  // Subscribe specifies the data to sync
  const message = model.at('hello.message');
  message.subscribe(err => {
    if (err) return next(err);
    message.createNull('');
    page.render();
  });
});
github triptec / derby-learn-by-example / lib / server / index.js View on Github external
var http = require('http')
  , path = require('path')
  , express = require('express')
  , gzippo = require('gzippo')
  , derby = require('derby')
  , auth = require('derby-auth')
  , app = require('../app')
  , serverError = require('./serverError')


// SERVER CONFIGURATION //

var expressApp = express()
  , server = module.exports = http.createServer(expressApp)

derby.use(derby.logPlugin)
derby.use(require('racer-db-mongo')); // This line is new

var store = derby.createStore({
  listen: server,
  db:      {type: 'Mongo', uri: process.env.MONGOHQ_URL || 'mongodb://localhost/snippets'}
})

//Authentication
auth.store(store);

var options, strategies;
strategies = {
  facebook: {
    strategy: require("passport-facebook").Strategy,
    conf: {
      clientID: process.env.FACEBOOK_KEY,

derby

MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers.

MIT
Latest version published 17 hours ago

Package Health Score

79 / 100
Full package analysis