代码拉取完成,页面将自动刷新
同步操作将从 0-hun/nodejs-cms 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var multipart = require('connect-multiparty');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var expressLayouts = require('express-ejs-layouts');
var Uploader = require('express-uploader');
app = express();
db = require('./common/config');
Main = require('./common/Main');
var admin = require('./routes/admin');
var routes = require('./routes/index');
var users = require('./routes/users');
var comment = require('./routes/comment');
var multipartMiddleware = multipart();
moment = require('moment');
var ueditor = require('ueditor-nodejs');
app.use('/ueditor/ue', ueditor({//这里的/ueditor/ue是因为文件件重命名为了ueditor,如果没改名,那么应该是/ueditor版本号/ue
configFile: '/ueditor/php/config.json',//如果下载的是jsp的,就填写/ueditor/jsp/config.json
mode: 'local', //本地存储填写local
// accessKey: 'Adxxxxxxx',//本地存储不填写,bcs填写
// secrectKey: 'oiUqt1VpH3fdxxxx',//本地存储不填写,bcs填写
staticPath: path.join(__dirname, 'public/uploads'), //一般固定的写法,静态资源的目录,如果是bcs,可以不填
// dynamicPath: '/blogpicture' //动态目录,以/开头,bcs填写buckect名字,开头没有/.路径可以根据req动态变化,可以是一个函数,function(req) { return '/xx'} req.query.action是请求的行为,uploadimage表示上传图片,具体查看config.json.
}));
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.set('layout', 'layouts/main');
app.use(expressLayouts);
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
cookie:{ httpOnly: true, maxAge: 1000*60*60},
secret: 'keyboard cat',
resave: false,
saveUninitialized: true
}));
app.use(function (req, res, next) {
req.query.page = req.query.page || 1;
req.query.size = req.query.size || 10;
res.locals.user = req.session.user || {};
res.locals.title = '简单的nodejs cms';
res.locals.err = {message: '', errors: {}};
res.locals.error = '';
res.locals.pager = {pages:[]};
res.locals.defaultImg = '/images/default.png';
next();
});
app.all('/upload',multipartMiddleware, function (req, res, next) {
console.log(req.files);
var uploader = new Uploader({
debug: true,
validate: true,
thumbnails: false,
thumbToSubDir: true,
tmpDir: __dirname + '/public/tmp',
publicDir: __dirname + '/public',
uploadDir: __dirname + '/public/uploads',
uploadUrl: '/uploads/',
thumbSizes: [140, [100, 100]]
});
uploader.uploadFile(req, function (data) {
res.send(JSON.stringify(data), {'Content-Type': 'text/plain'}, 200);
});
});
//app.use(require('flash')());
app.use('/', routes);
app.use('/admin', admin);
app.use('/users', users);
app.use('/comment', comment);
// catch 404 and forward to error handler
app.use(function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// 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('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。