我无法在解析服务器中的云代码功能中访问响应对象?

问题描述

搜索了很多东西,却找不到方法来使用解析服务器云代码(我正在使用解析服务器3.10.0版)访问云函数的响应对象。我想念什么吗?

这是每个快递开发商的基本需求。如何添加响应头,更改响应statusCode,发送不同的Content-Type,将流数据发送到响应等等等?

请帮助。谢谢

解决方法

这不是云代码功能的目的。如果您想自己处理express.js请求/响应以进行更多自定义使用,则只需将自定义路由或中间件安装到应用程序即可。像这样:

const express = require('express');
const ParseServer = require('parse-server').ParseServer;
const app = express();

const api = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev',// Connection string for your MongoDB database
  cloud: '/home/myApp/cloud/main.js',// Absolute path to your Cloud Code
  appId: 'myAppId',masterKey: 'myMasterKey',// Keep this key secret!
  fileKey: 'optionalFileKey',serverURL: 'http://localhost:1337/parse' // Don't forget to change to https if needed
});

// Serve the Parse API on the /parse URL prefix
app.use('/parse',api);

// Any custom middleware that you want as you'd normally do in any Express.js app
app.use('/your-custom-path',yourCustomMidleware);

app.listen(1337,function() {
  console.log('parse-server-example running on port 1337.');
});