Permalink
Browse files

fixed middleware

  • Loading branch information...
1 parent 490d092 commit b8b7f54424812167afc61a53fca47075b801d55a @debounce debounce committed Jul 1, 2012
Showing with 116 additions and 29 deletions.
  1. +32 −6 conf.js
  2. +37 −6 index.js
  3. +4 −0 models/db.json
  4. 0 models/index.js
  5. +5 −2 package.json
  6. +0 −8 public/css/style.css
  7. BIN public/img/favicon.ico
  8. +12 −0 public/index.html
  9. +0 −7 routes/index.js
  10. +26 −0 util.js
View
38 conf.js
@@ -1,6 +1,32 @@
-module.exports = {
- http: {
- port: 3000,
- host: '192.168.80.131'
- }
-};
+var path = require('path');
+
+
+var conf = {};
+
+conf.DEVELOPMENT = 'development';
+conf.PRODUCTION = 'production'
+
+conf.env = process.env.NODE_ENV || conf.DEVELOPMENT;
+
+conf.favicon = path.join('public', 'img', 'favicon.ico');
+
+conf.static = {};
+conf.static.maxAge = 120 * 24*60*60 * 1000; // 120 days
+conf.static.publicDir = path.join( __dirname, 'public' );
+
+conf.cookie = {};
+conf.cookie.secret = 'kl75758C29xPo66N70668DGeJ6iq5vi7d7S1p5ux123V';
+conf.cookie.key = 'simplebase.sid';
+conf.cookie.maxAge = 120 * 24*60*60 * 1000 // 120 days
+
+conf.http = {};
+conf.http.port = 3000;
+conf.http.host = '192.168.80.131';
+
+conf.mongo = {};
+conf.mongo.host = 'localhost';
+conf.mongo.port = 27017;
+conf.mongo.db = "simplebase";
+conf.mongo.url = "mongodb://"+conf.mongo.host+":"+conf.mongo.port+"/"+conf.mongo.db;
+
+module.exports = conf;
View
@@ -1,32 +1,63 @@
var express = require('express');
+var connect = require('connect');
+var MongoStore = require('connect-mongodb');
var routes = require('./routes');
var conf = require('./conf.js');
+var util = require('./util.js');
var app = module.exports = express.createServer();
+
// General Configuration
-app.configure(function(){
+app.configure( function () {
+ app.use(connect.favicon(conf.favicon, {
+ 'maxAge': conf.static.maxAge
+ }));
app.use(express.bodyParser());
+ app.use(connect.query());
+ app.use(express.logger('dev'));
app.use(express.methodOverride());
- app.use(express.static(__dirname + '/public'));
+ app.use(connect.cookieParser(conf.cookie.secret));
+ app.use(express.session({
+ 'secret': conf.cookie.secret,
+ 'key': conf.cookie.key,
+ 'cookie': {
+ 'maxAge': conf.cookie.maxAge,
+ },
+ 'store': new MongoStore({
+ 'url': conf.mongo.url
+ })
+ }));
});
// Developement Configuration
-app.configure('development', function(){
+app.configure(conf.DEVELOPMENT, function () {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+ app.use(express.static(conf.static.publicDir));
});
// Production Configuration
-app.configure('production', function(){
+app.configure(conf.PRODUCTION, function () {
app.use(express.errorHandler());
+ app.use(express.logger({
+ 'format': ':response-time ms - :date - :req[x-real-ip] - :method :url :user-agent / :referrer'
+ }));
+ app.use(connect.compress());
+ app.use(express.static(conf.static.publicDir, {
+ 'maxAge': conf.static.maxAge
+ }));
+ app.use(connect.staticCache());
});
// start http server
-app.listen(conf.http.port, conf.http.host, function(){
- console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
+app.listen(conf.http.port, conf.http.host, function () {
+ util.log('info', 'Express server started', {
+ 'address': app.address(),
+ 'settings': app.settings
+ });
});
View
@@ -0,0 +1,4 @@
+{
+ "models": [],
+ "relations": {}
+}
View
No changes.
View
@@ -13,8 +13,11 @@
"test": "mocha"
},
"dependencies": {
- "mocha": "*",
- "express": "*"
+ "mocha": "~1.2.2",
+ "express": "~2.5.11",
+ "connect": "~2.3.5",
+ "winston": "~0.6.1",
+ "express-session-mongo": "~0.0.1"
},
"devDependencies": {},
"optionalDependencies": {},
View
@@ -1,8 +0,0 @@
-body {
- padding: 50px;
- font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
-}
-
-a {
- color: #00B7FF;
-}
View
Binary file not shown.
View
@@ -0,0 +1,12 @@
+<!doctype html>
+<html lang="en">
+
+ <head>
+ <title>Simple Base</title>
+ <meta charset="UTF-8"/>
+ </head>
+
+ <body>
+ <h1> Hello Simple Base </h1>
+ </body>
+</html>
View
@@ -1,8 +1 @@
-/*
- * GET home page.
- */
-
-exports.index = function(req, res){
- res.render('index', { title: 'Express' })
-};
View
26 util.js
@@ -0,0 +1,26 @@
+var winston = require('winston');
+
+// configure winston logger
+winston.remove(winston.transports.Console);
+winston.add(winston.transports.Console, {
+ timestamp: true,
+ colorize: true
+});
+winston.add(winston.transports.File, {
+ filename: './logs/app.log',
+ level: 'error',
+ maxsize: 10 * 1024 * 1024, // max log filesize
+ colorize: true,
+ handleExceptions: true,
+ exitOnError: true,
+});
+
+
+// levels: info, warn, error
+var log = function () {
+ return winston.log.apply(winston, arguments);
+};
+
+
+// public api
+exports.log = log;

0 comments on commit b8b7f54

Please sign in to comment.