代码拉取完成,页面将自动刷新
同步操作将从 doramart/DoraCMS 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*引用模块*/
var express = require('express');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var compression = require('compression');
var routes = require('./routes/index');
//用户相关功能
var users = require('./routes/users');
var admin = require('./routes/admin');
var content = require('./routes/content');
//验证器
var validat = require('./routes/validat');
//系统功能支持
var system = require('./routes/system');
//站点配置
var settings = require("./models/db/settings");
var siteFunc = require("./models/db/siteFunc");
//文件操作对象
var fs = require('fs');
//时间格式化
var moment = require('moment');
var filter = require('./util/filter');
/*模板引擎*/
var partials = require('express-partials');
/*实例化express对象*/
var app = express();
//ueditor注册
var ueditor = require('ueditor-nodejs');
app.use('/ueditor/ue', ueditor({//这里的/ueditor/ue是因为文件件重命名为了ueditor,如果没改名,那么应该是/ueditor版本号/ue
configFile: '/ueditor/jsp/config.json',//如果下载的是jsp的,就填写/ueditor/jsp/config.json
mode: 'local', //本地存储填写local
accessKey: '',//本地存储不填写,bcs填写
secrectKey: '',//本地存储不填写,bcs填写
staticPath: path.join(__dirname, 'public'), //一般固定的写法,静态资源的目录,如果是bcs,可以不填
dynamicPath: '/blogpicture' //动态目录,以/开头,bcs填写buckect名字,开头没有/.路径可以根据req动态变化,可以是一个函数,function(req) { return '/xx'} req.query.action是请求的行为,uploadimage表示上传图片,具体查看config.json.
}));
// view engine setup
//静态压缩
app.use(compression());
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(partials());
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json({limit: '50mb'})); // 限制上传5M
app.use(bodyParser.urlencoded({ extended: false , limit: '50mb' }));
app.use(cookieParser(settings.session_secret));
//解决异步层次混乱问题
app.use(require('express-promise')());
app.use(session({
secret: settings.session_secret,
store: new RedisStore({
port: settings.redis_port,
host: settings.redis_host,
pass : settings.redis_psd,
ttl: 1800 // 过期时间
}),
resave: true,
saveUninitialized: true
}));
app.use(filter.authUser);
app.use(function(req, res, next){
// 针对注册会员
res.locals.logined = req.session.logined;
res.locals.userInfo = req.session.user;
// 针对管理员
res.locals.adminlogined = req.session.adminlogined;
res.locals.adminUserInfo = req.session.adminUserInfo;
// 指定站点域名
res.locals.myDomain = req.headers.host;
next();
});
//配置站点地图和robots抓取
app.get('/sitemap.xml',function(req, res, next) {
siteFunc.setDataForSiteMap(req, res);
});
app.get('/robots.txt',function(req, res, next) {
var stream=fs.createReadStream('./robots.txt',{flags:'r'});
stream.pipe(res);
});
//数据格式化
app.locals.myDateFormat = function(date){
moment.locale('zh-cn');
return moment(date).startOf('hour').fromNow();
};
app.use(express.static(path.join(__dirname, 'public')));
/*指定路由控制*/
app.use('/admin', validat);
app.use('/admin', admin);
app.use('/users', users);
app.use('/', routes);
app.use('/content', content);
app.use('/system',system);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
console.log(err);
res.render('web/public/do404', siteFunc.setDataForError(req, res, '找不到页面' ,err.message));
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('web/public/do500', siteFunc.setDataForError(req, res, '出错啦!' ,err.message));
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('web/public/do500', siteFunc.setDataForError(req, res, '出错啦!' , err.message));
});
module.exports = app;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。