Rich text node js

  1. Installation rich text
	npm i ueditor --save
  1. The introduction module
	let  bodyParser = require("body-parser")
	let ueditor = require("ueditor")
  1. app.use(bodyParser.urlencoded({ extended: true })) app.use(bodyParser.json());
  2. `app.use(bodyParser.urlencoded({
    extended: true
    }));
    app.use(bodyParser.json());
    // view engine setup

// upload the picture or the picture file server address
app.use (express.static (__ dirname + '/ static'))
// static files
app.use (express.static (__ dirname + '/ public'));
// ueditor profile static server address
app.use (express.static (__ dirname + ' / nodejs'))

app.all("", function(req, res, next){
res.header(“Access-Control-Allow-Origin”, '
’);
next()
})

app.use ( "/ ueditor / UE", ueditor (path.join (__ dirname, 'static'), function (REQ, RES, Next) {
// client upload file is provided
var imgDir = '/ img / ueditor /'
var = __dirname imgDir + // '/ Upload'
the console.log (imgDir)
var ActionType = req.query.action;
IF (ActionType === 'uploadimage' || ActionType === 'UploadFile' || === ActionType 'uploadvideo') {
var FILE_URL = imgDir; // default image upload address
/ other address formats to upload /
IF (ActionType === 'UploadFile') {
// FILE_URL __dirname + = '/ File'
FILE_URL = '/ File / ueditor / '; // attachment
}
IF (ActionType ===' uploadvideo ') {
// FILE_URL __dirname + =' / video '; // video
file_url =' / video / ueditor / '; // video
}
res.ue_up (file_url); // Just enter your address to be saved. Ueditor save operation to do
res.setHeader ( 'the Content-the Type', 'text / HTML');
}
// image list request initiated by the client
the else IF (req.query.action === 'ListImage') {
var = imgDir dir_url;
res.ue_list (dir_url); // client lists all images in the catalog dir_url
}
// client initiating other requests
the else {
res.setHeader ( 'the Content-the Type', 'file application / JSON') ;
res.redirect ( '/ config.json');
}
})); `

Published 50 original articles · won praise 23 · views 1254

Guess you like

Origin blog.csdn.net/qq_44698161/article/details/102566282