【发布时间】:2020-11-01 12:05:43
【问题描述】:
我搜索了很多,但找不到在解析服务器云代码中访问云函数响应对象的方法(我使用的是解析服务器版本 3.10.0)。我错过了什么?
这是每个快递开发人员的基本需求。如何添加响应标头、更改响应 statusCode、发送不同的 Content-Type、管道流数据到响应等?
请帮忙。谢谢
【问题讨论】:
标签: node.js express parse-server parse-cloud-code
我搜索了很多,但找不到在解析服务器云代码中访问云函数响应对象的方法(我使用的是解析服务器版本 3.10.0)。我错过了什么?
这是每个快递开发人员的基本需求。如何添加响应标头、更改响应 statusCode、发送不同的 Content-Type、管道流数据到响应等?
请帮忙。谢谢
【问题讨论】:
标签: node.js express parse-server parse-cloud-code
这不是云代码功能的目的。如果您想自己处理 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.');
});
【讨论】:
app.js 文件中,其中 var app 已经可用。