Created
September 11, 2012 12:15
-
-
Save ag4ve/3697982 to your computer and use it in GitHub Desktop.
flatiron app
This file contains hidden or 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 path = require('path'), | |
flatiron = require('flatiron'), | |
director = require('director'), | |
ecstatic = require('ecstatic'), | |
connect = require('connect'), | |
app = flatiron.app, | |
plugins = flatiron.plugins; | |
var routes = require('./lib/routes.js'), | |
models = require('./lib/models.js'); | |
global.app = app; | |
global.models = models; | |
app.config.file({ file: path.join(__dirname, 'config', 'config.json') }); | |
app.use(plugins.http); | |
app.http.before = [ | |
connect.favicon(), | |
connect.logger(), | |
ecstatic(__dirname + '/public', opts = { | |
cache: 600, | |
autoIndex: false | |
}), | |
connect.cookieParser(), | |
connect.bodyParser(), | |
]; | |
// start db from routes | |
models.init(); | |
// mount routes | |
app.router.mount(routes); | |
app.start(3000); | |
var addr = app.server.address(); | |
app.log.info('Listening on http://' + addr.address + ':' + addr.port); |
This file contains hidden or 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 routes = { | |
'/fr': { | |
'get': function () { | |
var that = this; | |
models.fr.get({}, null, function (err, data) { | |
if (err) { | |
app.log.warn(err); | |
that.res.end("fail"); | |
} else { | |
that.res.end(JSON.stringify(data)); | |
} | |
} ); | |
}, | |
'post': function() { | |
var that = this; | |
console.log("json stringify: " + JSON.stringify(that.req.body)); | |
console.log("trying something" + JSON.parse(that.req.body)); | |
var input = JSON.parse(that.req.body); | |
console.log("json parse body: " + input); | |
models.fr.put(input, function (err, input) { | |
if (err) { | |
app.log.warn(err); | |
that.res.end("fail"); | |
} else { | |
that.res.end("ok"); | |
} | |
} ); | |
}, | |
}, | |
'/test': { | |
"get": function () { | |
this.res.end(JSON.stringify({ "hello": "world" })); | |
}, | |
}, | |
}; | |
module.exports = routes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment