小编Blu*_*Pie的帖子

Firebase 函数先解析请求正文,然后才能在 Express 中处理它

我正在尝试处理 Firebase 函数中的无效请求,因此使用无效的 JSON 发出发布请求,目的是在 Express 中处理它。但在到达 Express 层之前,我收到了400 错误“SyntaxError: Unexpected token a in JSON atposition 20”,最糟糕的是该函数运行了 60 秒,直到遇到超时错误。

我的职能

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 = …
Run Code Online (Sandbox Code Playgroud)

express firebase google-cloud-functions

5
推荐指数
1
解决办法
522
查看次数

标签 统计

express ×1

firebase ×1

google-cloud-functions ×1