加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.js 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
Cherokee 提交于 2014-07-05 11:49 . use compress
/**
* Module dependencies.
*/
var express = require('express');
var http = require('http');
var path = require('path');
var fs = require('fs');
var RedisStore = require('connect-redis')(express);
var routes = require('./routes');
var settings = require('./settings.json');
var ejser = require('./middlewares/ejser.js');
var run_instance = function(port){
var app = express();
// all environments
app.set('port', port || process.env.PORT);
app.set('views', path.join(__dirname, 'views'));
//app.set('view engine', 'ejs');
app.engine('.html', ejser.EJS().renderFile);//or app.engine('.html', require('ejs').__express);
app.set('view engine', 'html');//change ejs template suffix to .html
app.set('jsonp callback', true);
app.use(express.favicon(path.join(__dirname,'public/images/favicon.ico')));
app.use(express.compress());
//logger
var accessLogfile = fs.createWriteStream('logs/access.log', {flags: 'a'});
var errorLogfile = fs.createWriteStream('logs/error.log', {flags: 'a'});
app.use(express.logger({stream: accessLogfile}));
app.configure('production', function() {
app.use(function(err, req, res, next){
var meta = '[' + new Date() + '] ' + req.url + '\n';
errorLogfile.write(meta + err.stack + '\n');
next();
});
});
//app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.bodyParser({ keepExtensions: true,uploadDir:'./public/uploads'}));
app.use(express.cookieParser(settings['session_secret']));
//app.use(express.session());
app.use(express.session({
secret:settings['session_secret'],
store:new RedisStore(settings['session_redis_db'])
}));
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
routes(app);//mapping routes
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
}
exports.run = run_instance;
if(!module.parent) {
run_instance(80);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化