forked from nswbmw/N-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2379269
Showing
638 changed files
with
100,789 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var express = require('express'); | ||
var routes = require('./routes'); | ||
var http = require('http'); | ||
var path = require('path'); | ||
var MongoStore = require('connect-mongo')(express); | ||
var settings = require('./settings'); | ||
var flash = require('connect-flash'); | ||
|
||
var app = express(); | ||
|
||
// all environments | ||
app.set('port', process.env.PORT || 3000); | ||
app.set('views', __dirname + '/views'); | ||
app.set('view engine', 'ejs'); | ||
app.use(flash()); | ||
app.use(express.favicon(__dirname + '/public/images/favicon.ico')); | ||
app.use(express.logger('dev')); | ||
app.use(express.bodyParser({ keepExtensions: true, uploadDir: './public/images' })); | ||
app.use(express.methodOverride()); | ||
app.use(express.cookieParser()); | ||
app.use(express.session({ | ||
secret: settings.cookieSecret, | ||
key: settings.db, | ||
cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days | ||
store: new MongoStore({ | ||
db: settings.db | ||
}) | ||
})); | ||
app.use(app.router); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
// development only | ||
if ('development' == app.get('env')) { | ||
app.use(express.errorHandler()); | ||
} | ||
|
||
http.createServer(app).listen(app.get('port'), function(){ | ||
console.log('Express server listening on port ' + app.get('port')); | ||
}); | ||
|
||
routes(app); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var mongodb = require('./db'); | ||
|
||
function Comment(name, day, title, comment) { | ||
this.name = name; | ||
this.day = day; | ||
this.title = title; | ||
this.comment = comment; | ||
} | ||
|
||
module.exports = Comment; | ||
|
||
//存储一条留言信息 | ||
Comment.prototype.save = function(callback) { | ||
var name = this.name, | ||
day = this.day, | ||
title = this.title, | ||
comment = this.comment; | ||
//打开数据库 | ||
mongodb.open(function (err, db) { | ||
if (err) { | ||
callback(err); | ||
} | ||
//读取 posts 集合 | ||
db.collection('posts', function (err, collection) { | ||
if (err) { | ||
mongodb.close(); | ||
callback(err); | ||
} | ||
//通过用户名、时间及标题查找文档,并把一条留言对象添加到该文档的 comments 数组里 | ||
collection.update({ | ||
"name": name, | ||
"time.day": day, | ||
"title": title | ||
}, { | ||
$push: {"comments": comment} | ||
} , function (err, result) { | ||
mongodb.close(); | ||
callback(null); | ||
}); | ||
}); | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var settings = require('../settings'), | ||
Db = require('mongodb').Db, | ||
Connection = require('mongodb').Connection, | ||
Server = require('mongodb').Server; | ||
module.exports = new Db(settings.db, new Server(settings.host, Connection.DEFAULT_PORT, {})); |
Oops, something went wrong.