ueditor_route.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * ueditor相关路由
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/9/25
  6. * @version
  7. */
  8. import Express from "express";
  9. const router = Express.Router();
  10. const ueditor = require("ueditor");
  11. const path = require('path');
  12. module.exports = function (app) {
  13. const uploadPath = path.join(app.locals.rootDir, 'public');
  14. // action定义区域
  15. router.get('/ue', ueditor(uploadPath, function (req, res, next) {
  16. res.setHeader('Content-Type', 'application/json');
  17. res.redirect('/lib/ueditor/nodejs/config.json')
  18. }));
  19. router.post('/ue', ueditor(uploadPath, function (req, res, next) {
  20. // ueditor 客户发起上传图片请求
  21. if (req.query.action === 'uploadimage') {
  22. let imgUrl = '/public/images/ueditor/';
  23. res.ue_up(imgUrl); //你只要输入要保存的地址 。保存操作交给ueditor来做
  24. }
  25. // 客户端发起图片列表请求
  26. else if (req.query.action === 'listimage') {
  27. let dirUrl = '/images/ueditor/';
  28. res.ue_list(dirUrl); // 客户端会列出 dir_url 目录下的所有图片
  29. }
  30. }));
  31. app.use("/ueditor", router);
  32. };