我在Express中有以下中间件:
app.use(morgan('combined', util.getLogStream()));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({ limit: '50mb' }));
app.use('/api', router);
app.use(express.static(__dirname + '/server/landing'));
当我尝试将表情符号发布到我的服务器时,行app.use(bodyParser.json({ limit: '50mb' }));
会中断并崩溃服务器崩溃。我正在寻找一种方法来处理Express或body解析器中的表情符号,但似乎对此没什么支持。如何让身体解析器解析表情符号?
编辑:
这是我通过curl发送到我的Express服务器的消息有效负载
curl --data '{"x": 10, "y":10, "z":10, "message": "", "userToken": "Marine"}' --header "Content-Type:application/json” localhost:3000/api/messages
**Error message**
Uncovery listening at http://:::3000
SyntaxError: Unexpected token
at Object.parse (native)
at parse (/Users/user/Documents/uncovery/node_modules/body-parser/lib/types/json.js:84:17)
at /Users/user/Documents/uncovery/node_modules/body-parser/lib/read.js:102:18
at IncomingMessage.onEnd (/Users/user/Documents/uncovery/node_modules/body-parser/node_modules/raw-body/index.js:149:7)
at IncomingMessage.g (events.js:199:16)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
的index.html
var http = require('http');
var morgan = require('morgan');
var express = require('express');
var socketIO = require('socket.io');
var bodyParser = require('body-parser');
var util = require('./server/core/utilities.js');
var router = require('./server/routes/router.js');
var sockets = require('./server/routes/sockets.js');
var app = express();
var server = http.Server(app);
app.use(morgan('combined', util.getLogStream()));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.json);
app.use('/api', router);
app.use(express.static(__dirname + '/server/landing'));
var io = socketIO(server);
sockets.initialize(io);
server.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Uncovery listening at http://%s:%s', host, port);
});