-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (55 loc) · 1.83 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var express = require('express');
var port = process.env.PORT || 3000;
var mongoose = require('mongoose');
var path = require('path');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var mongoStore = require('connect-mongo')(session);
var logger = require('morgan');
var ueditor = require('ueditor');
mongoose.connect('mongodb://localhost/ultimate')
var app = express();
app.set('views', './app/views/pages');
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser());
app.use(cookieParser());
app.use(session({
secret: 'ultimate',
store: new mongoStore({
url: 'mongodb://localhost/ultimate',
collection: 'sessions'
})
}));
app.use("/libs/ueditor/ue", ueditor(path.join(__dirname, 'public'), function(req, res, next){
// ueditor 客户发起上传图片请求
if (req.query.action === 'uploadimage') {
var foo = req.ueditor;
var imgname = req.ueditor.filename;
var img_url = '/images/ueditor/';
//你只要输入要保存的地址 。保存操作交给ueditor来做
res.ue_up(img_url);
}
// 客户端发起图片列表请求
else if (req.query.action === 'listimage') {
var dir_url = '/images/ueditor/';
// 客户端会列出 dir_url 目录下的所有图片
res.ue_list(dir_url);
}
// 客户端发起其它请求
else {
res.setHeader('Content-Type', 'application/json');
res.redirect('/libs/ueditor/config.json');
}
}));
//登陆处理程序
if (app.get('env') === 'development') {
app.use(logger(':method :url :status'));
app.locals.pretty = true;
mongoose.set('debug', true);
app.set('showStackError', true);
}
require('./config/routes')(app);
app.listen(port);
console.log('started at '+ port);