Skip to content

Instantly share code, notes, and snippets.

@plmrry
Created February 10, 2016 23:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plmrry/4ac578e00857bd102036 to your computer and use it in GitHub Desktop.
Save plmrry/4ac578e00857bd102036 to your computer and use it in GitHub Desktop.
Tiny LoopBack
var loopback = require('loopback');
var explorer = require('loopback-component-explorer');
var app = module.exports = loopback();
app.set('host', '0.0.0.0');
app.set('port', '3000');
app.set('restApiRoot', '/api');
app.set('legacyExplorer', false);
app.dataSource('db', {
"name": "db",
"connector": "memory"
});
app.dataSource('mysqlDs', {
"name": "mysqlDs",
"connector": "mysql",
"host": "demo.strongloop.com",
"port": 3306,
"database": "getting_started",
"username": "demo",
"password": "L00pBack"
});
var CoffeeShop = app.loopback.createModel({
"name": "CoffeeShop",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"city": {
"type": "string",
"required": true
}
}
});
app.model(CoffeeShop, { dataSource: 'mysqlDs' });
app.model(app.loopback.ACL, {
"dataSource": "db",
"public": false
});
app.middlewareFromConfig(loopback.rest, { paths: [ '/api' ], phase: 'routes' });
explorer(app, { basePath: '/api', mountPath: '/explorer' });
var router = app.loopback.Router();
router.get('/', app.loopback.status());
app.use(router);
app.enableAuth();
app.listen(function() {
app.emit('started');
console.log('Web server listening at: %s', app.get('url'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment