我尝试在Firebase函数中处理无效请求,使用带有无效JSON的post请求,以便在express中处理它。但是,在它到达express层之前,我收到了400错误“SyntaxError:JSON中的位置20处出现意外令牌a”,最糟糕的是该函数运行60秒,直到它超时引发错误。
我的函数
无效的JSON。
我猜这与 "This parsing is done by the following body parsers:" 所述的 https://firebase.google.com/docs/functions/http-events#read_values_from_the_request 有关。
我的函数
import * as functions from 'firebase-functions';
import * as express from 'express';
import * as admin from 'firebase-admin';
admin.initializeApp();
const app = express();
app.use((err: any, req: any, res: any, next: any) => {
res.json({ error: 'invalid request' });
next(err);
});
app.post('/test', (req: any, res: any) => {
res.json({ error: 'invalid request' });
res.end();
return;
});
const server = functions.runWith({ maxInstances: 100 }).https.onRequest(app);
export { server as api };
无效的JSON。
{
"es":"adfasdf"asdf
}
我猜这与 "This parsing is done by the following body parsers:" 所述的 https://firebase.google.com/docs/functions/http-events#read_values_from_the_request 有关。
import express from 'express';
。 - Dharmaraj