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
Showing
8 changed files
with
71 additions
and
60 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
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 |
---|---|---|
@@ -1,56 +1,59 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var path = require('path'); | ||
|
||
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 favicon = require('serve-favicon'); | ||
var logger = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
var session = require('express-session'); | ||
var MongoStore = require('connect-mongo')(session); | ||
var flash = require('connect-flash'); | ||
var multer = require('multer'); | ||
|
||
var route = require('./routes/index'); | ||
var settings = require('./settings'); | ||
|
||
var fs = require('fs'); | ||
var accessLog = fs.createWriteStream('access.log', {flags: 'a'}); | ||
var errorLog = fs.createWriteStream('error.log', {flags: 'a'}); | ||
|
||
var app = express(); | ||
|
||
// all environments | ||
app.set('port', process.env.PORT || 3000); | ||
app.set('views', __dirname + '/views'); | ||
app.set('views', path.join(__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.logger({stream: accessLog})); | ||
app.use(express.bodyParser({ keepExtensions: true, uploadDir: './public/images' })); | ||
app.use(express.methodOverride()); | ||
app.use(express.cookieParser()); | ||
app.use(express.session({ | ||
app.use(favicon(__dirname + '/public/images/favicon.ico')); | ||
app.use(logger('dev')); | ||
app.use(logger({stream: accessLog})); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(multer({ | ||
dest: './public/images', | ||
rename: function (fieldname, filename) { | ||
return filename; | ||
} | ||
})); | ||
app.use(cookieParser()); | ||
app.use(session({ | ||
secret: settings.cookieSecret, | ||
key: settings.db,//cookie name | ||
cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days | ||
store: new MongoStore({ | ||
db: settings.db | ||
db: settings.db, | ||
host: settings.host, | ||
port: settings.port | ||
}) | ||
})); | ||
app.use(app.router); | ||
app.use(flash()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
route(app); | ||
|
||
app.use(function (err, req, res, next) { | ||
var meta = '[' + new Date() + '] ' + req.url + '\n'; | ||
errorLog.write(meta + err.stack + '\n'); | ||
next(); | ||
}); | ||
|
||
// development only | ||
if ('development' == app.get('env')) { | ||
app.use(express.errorHandler()); | ||
} | ||
|
||
http.createServer(app).listen(app.get('port'), function(){ | ||
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
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 |
---|---|---|
@@ -1,16 +1,23 @@ | ||
{ | ||
"name": "blog", | ||
"version": "0.0.1", | ||
"name": "N-blog", | ||
"version": "1.0.0", | ||
"private": true, | ||
"description": "N-blog for express4.x", | ||
"scripts": { | ||
"start": "node app.js" | ||
"start": "node app" | ||
}, | ||
"dependencies": { | ||
"express": "^3.4.4", | ||
"ejs": "*", | ||
"mongodb": "*", | ||
"connect-mongo": "*", | ||
"connect-flash": "*", | ||
"markdown": "*" | ||
"express": "4.10.2", | ||
"body-parser": "1.9.0", | ||
"cookie-parser": "1.3.3", | ||
"morgan": "1.3.1", | ||
"serve-favicon": "2.1.5", | ||
"ejs": "1.0.0", | ||
"markdown": "0.5.0", | ||
"mongodb": "1.4.15", | ||
"express-session": "1.9.1", | ||
"connect-flash": "0.1.1", | ||
"connect-mongo": "0.4.1", | ||
"multer": "0.1.6" | ||
} | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
cookieSecret: 'myblog', | ||
db: 'blog', | ||
host: 'localhost' | ||
host: 'localhost', | ||
port: 27017 | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<%- include header %> | ||
<p> | ||
<% posts.forEach(function (tag, index) { %> | ||
<a class="tag" href="/tags/<%= tag %>"><%= tag %></a> | ||
<% }) %> | ||
</p> | ||
<%- include footer %> |