我在 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 parser 中处理表情符号的方法,但似乎对此几乎没有支持。如何让身体解析器解析表情符号?
编辑:
这是我通过 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)
索引.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);
});