我的快递:
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var less = require("express-less")
var session = require("express-session")
var FileStore = require("session-file-store")(session)
var router = require('./router');
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use('/css', less(__dirname + '/less'));
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
secret: "secret message that is obviously not the one i'm using in my code",
resave: true,
saveUninitialized: true
}));
app.use('/', router);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
(这只是快速生成器生成的代码,但增加了一些内容)
行
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
应该将最大限制设置为我设置的最大限度,但是,我已经远程搜索了互联网并且还没有遇到可行的解决方案。当我通过XMLHttpRequest向服务器发送大于100kb的图像时,我得到413(有效负载太大)错误。
我还建议我使用'MB'代替'mb',但这不起作用。