Created
September 20, 2012 21:51
-
-
Save robert52/3758573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flatiron = require('flatiron'), | |
resourceful = require('resourceful'), | |
plates = require('plates'), | |
path = require('path'), | |
ecstatic = require('ecstatic'), | |
app = flatiron.app, | |
config, | |
m = {}; | |
/** | |
* Config file | |
*/ | |
app.config.file({ file: path.join(__dirname, './config/config.json')}); | |
/** | |
* Flatiron plugins | |
*/ | |
app.use(flatiron.plugins.http, { | |
before: [ | |
ecstatic(path.join(__dirname, './public'), {autoIndex: false}) | |
] | |
}); | |
app.use(flatiron.plugins.resourceful, { | |
//root: __dirname, | |
engine: 'memory' | |
}); | |
/** | |
* Registering Models | |
*/ | |
['user'].forEach(function(model) { | |
require('./app/models/' + model + '_model')(resourceful); | |
}); | |
/** | |
* Registering routers | |
*/ | |
['main', 'user'].forEach(function(router) { | |
require('./app/routers/' + router + '_router')(app, resourceful, plates, config); | |
}); | |
app.start(app.config.get('port') || 3000, function(err) { | |
if (err) { | |
throw err; | |
} | |
var addr = app.server.address(); | |
app.log.info('Listening on http://' + addr.address + ':' + addr.port); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//user_model.js | |
module.exports = function(resourceful) { | |
var User = resourceful.define('user', function() { | |
this.string('username').required(true); | |
this.string('password').required(true); | |
this.string('email', { format: 'email', requierd: true}); | |
}); | |
return User; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//user_router.js | |
var UserRouter = function(app, resourceful, plates, config) { | |
var resources = resourceful.resources; | |
//this one works but can .save() the resource | |
// var user = new(resources.User)({ | |
// username: 'Bob', | |
// password: 'bob!234', | |
// email: '[email protected]' | |
// }); | |
var user = resources.User.create({ | |
id : 'Test' | |
}, function(err, user) { | |
user = { | |
username: 'Bob', | |
password: 'bob!234', | |
email: '[email protected]' | |
}; | |
console.log(err, user); | |
user.save(function(err, result) { | |
console.log(err, result); | |
}); | |
}); | |
/** | |
* Get all users | |
*/ | |
app.router.get('/users', function() { | |
var users = resources.User.all(); | |
this.res.json(200, users); | |
}); | |
}; | |
module.exports = UserRouter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment