【问题标题】:I cannot access to response object in a cloud code function in parse-server?我无法访问解析服务器中云代码函数中的响应对象?
【发布时间】:2020-11-01 12:05:43
【问题描述】:

我搜索了很多,但找不到在解析服务器云代码中访问云函数响应对象的方法(我使用的是解析服务器版本 3.10.0)。我错过了什么?

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

请帮忙。谢谢

【问题讨论】:

    标签: node.js express parse-server parse-cloud-code


    【解决方案1】:

    这不是云代码功能的目的。如果您想自己处理 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.');
    });
    

    【讨论】:

    • 感谢@Davi,但实际上我想在 back4App 中使用它。但是我读到您可以激活托管选项以使用快递。 back4App 做得很好,它的结构非常好!
    • 谢谢!只是为了确保您已经看到,在 Back4App 中,启用托管选项后,您可以将自定义端点/中间件挂载到 app.js 文件中,其中 var app 已经可用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多