Forked from gabrielstuff/controllers_config.js
Last active
December 17, 2015 08:19
-
-
Save jwerle/5579443 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 mongoose = require('mongoose'), | |
Config = mongoose.model('Config') | |
exports.create = function(req, res) { | |
var conf = new Config(req.body); | |
console.log(conf) | |
conf.save(function(err) { | |
if (err) throw new Error('Error while saving option'); | |
console.log("Ouray !"); | |
res.send(conf) | |
}) | |
} |
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 mongoose = require('mongoose'); | |
require('./model_config'); | |
c = require('./controllers_config'); | |
express = require('express') | |
app = express() | |
app.listen(4000); | |
app.post('/create', c.create); | |
mongoose.connect('localhost', 'test') |
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
//The model : | |
var mongoose = require('mongoose') | |
, Schema = mongoose.Schema | |
var ConfigSchema = new Schema({ | |
config: Schema.Types.Mixed | |
, createdAt: {type : Date, default : Date.now} | |
}) | |
mongoose.model('Config', ConfigSchema) |
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
// shell 1 | |
$ node index.js | |
// shell 2 | |
$ curl -i -X POST -d 'config[title]=sas&config[facebook][clientID]=soapjs&config[facebook][clientSecret]=&config[facebook][callbackURL]=&config[pixcube][path]=booooob&config[cube][www]=' localhost:4000/create | |
HTTP/1.1 200 OK | |
X-Powered-By: Express | |
Content-Type: application/json; charset=utf-8 | |
Content-Length: 94 | |
Date: Tue, 14 May 2013 20:53:43 GMT | |
Connection: keep-alive | |
{ | |
"__v": 0, | |
"_id": "5192a4571a8bc33144000001", | |
"createdAt": "2013-05-14T20:53:43.475Z" | |
} | |
// shell 1 | |
{ _id: 5192a4571a8bc33144000001, | |
createdAt: Tue May 14 2013 16:53:43 GMT-0400 (EDT) } | |
Ouray ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment