Skip to content

Instantly share code, notes, and snippets.

@djyde
Created September 25, 2011 05:36
Show Gist options
  • Save djyde/1240276 to your computer and use it in GitHub Desktop.
Save djyde/1240276 to your computer and use it in GitHub Desktop.
weblog
var web = require('webjs'),
mongoose = require('mongoose'),
config = require('./config'),
EventProxy = require('EventProxy.js').EventProxy,
Schema = mongoose.Schema;
mongoose.connect('mongodb://' + config.db.host + ':' + config.db.port + '/weblog');
var Comment = new Schema({
author: String,
content: String,
date: Date
}),
Post = new Schema({
id: String,
title: String,
content: String,
date: Date,
comments: [Comment]
}),
Info = new Schema({
type: String,
value: String
});
var Posts = mongoose.model('Posts', Post),
Infos = mongoose.model('Infos', Info);
var urlRouter = {
'post/:title': 'views/post.html'
},
getRouter = {
'getpost': function (req, res) {
Posts.findOne({id: req.qs.id}, function (err, post) {
res.sendJSON(post);
});
},
'getposts': function (req, res) {
Posts.find({id: req.qs.id}, function (err, post) {
res.sendJSON(post);
});
},
'getinfo': function (req, res) {
Infos.findOne({type: req.qs.type}, function (err, info) {
res.send(info.value);
});
},
'/': function (req, res) {
var index = new EventProxy(),
render = function (posts, infos) {
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment