Parse.Cloud.httpRequest 功能的 Parse Server Cloud 代码问题

问题描述 投票:0回答:1

我有一个带有解析服务器后端的 Angular 应用程序。

在本地环境中,一切都比预期的要好,直到我决定使用 LetsEncrypt Ssl 安装 Nginx 作为代理。

我的应用程序在构建后托管在网络服务器上,网址为 https://admin.my-app.ch

我的解析服务器位于 DigitalOcean 托管的 docker 容器上,可通过 Nginx 代理在 https://my-app-api.ch 访问。

但是现在我的云代码(保存之前),特别是对于图像(文件)管理(通过 FSAdapter),向我发送连接超时。

我不明白为什么,因为大多数解析服务器请求都有效。

例如,我可以列出并创建产品或客户,但当我尝试添加图像时,连接 ETIMEDOUT (MY_PUBLIC_IP:443)。 这是唯一可以收到的错误。

奇怪的是图片成功上传到解析服务器的./files文件夹中。

另一件事,我无法在浏览器上进行刷新。当我这样做时,我收到 404 错误。

我认为这是一个 nginx.conf 问题,但我很新。

这是我的 nginx.conf

events {
   worker_connections 1024;
}
http{
        server_tokens off;
        charset utf-8;

        # HTTP - redirect all requests to HTTPS
        server {
                listen 80;
                listen [::]:80;
                return 301 https://$host$request_uri;
        }

        # HTTPS - serve HTML from /usr/share/nginx/html, proxy requests to /parse/
        # through to Parse Server
        server {
                        listen 443 ssl http2;

                        server_name my-app-api.ch ;

                        root /usr/share/nginx/html;
                        index index.html index.htm;

                        # Use certificate and key provided by Let's Encrypt:
                        ssl_certificate /etc/letsencrypt/live/my-app-api.ch/fullchain.pem;
                        ssl_certificate_key /etc/letsencrypt/live/my-app-api.ch/privkey.pem;

                        # Pass requests to Parse Server instance at localhost:1337
                        location / {
                                        # prevents 502 bad gateway error
                                        proxy_buffers 8 32k;
                                        proxy_buffer_size 64k;

                                        proxy_set_header X-Real-IP $remote_addr;
                                        proxy_set_header Access-Control-Allow-Origin '*';
                                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                                        proxy_set_header X-NginX-Proxy true;
                                        proxy_pass http://172.20.0.5:1337/;
                                        proxy_ssl_session_reuse off;
                                        proxy_set_header Host $http_host;
                                        proxy_redirect off;

                                        # enables WS support
                                        proxy_http_version 1.1;
                                        proxy_set_header Upgrade $http_upgrade;
                                        proxy_set_header Connection "upgrade";

                                        proxy_read_timeout 999999999;
        #                                       try_files $uri $uri/ =404;
                        }
                        location ~ /.well-known/acme-challenge/ {
                                root /var/www/certbot;
                        }

                #       location / {
                #               try_files $uri $uri/ =404;
                #       }
        }
}

解析服务器的配置如下:

databaseURI: databaseUri,
    cloud: __dirname + '/cloud/main.js',
    appId: process.env.APP_ID,
    masterKey: process.env.MASTER_KEY,
    readOnlyMasterKey: process.env.READ_ONLY_MASTER_KEY,
    serverURL: `http://localhost:${process.env.PORT}/api`,
    publicServerURL: 'https://my-app-api.ch' + '/api',
    directAccess: true,
    fileUpload: {
      enableForPublic: true,
      enableForAnonymousUser: true,
      enableForAuthenticatedUser: true,
    },

这是我的云代码的示例(在本地环境中工作。)

const sharp = require('sharp')
const Utils = require('../utils')

Parse.Cloud.beforeSave('SlideImage', async (req) => {

  const obj = req.object
  const attrs = obj.attributes
  const user = req.user

  const isAdmin = await Utils.isAdmin(user)
  if (!isAdmin && !req.master) throw 'Not Authorized'

  if (!obj.existed()) {
    const acl = new Parse.ACL()
    acl.setPublicReadAccess(true)
    acl.setRoleWriteAccess('Admin', true)
    obj.setACL(acl)
  }

  if (obj.dirty('image') && obj.get('image')) {

    const { buffer } = await Parse.Cloud.httpRequest({
      url: attrs.image.url()
    })

    const imageResizedData = await sharp(buffer)
      .jpeg({ quality: 70, progressive: true })
      .resize({
        width: 1200,
        withoutEnlargement: true,
        fit: 'inside',
      })
      .toBuffer()

    const imageThumbData = await sharp(buffer)
      .jpeg({ quality: 70, progressive: true })
      .resize({
        width: 200,
        height: 200,
        withoutEnlargement: true,
        fit: 'inside',
      })
      .toBuffer()

    const file = new Parse.File('image.jpg', {
      base64: imageResizedData.toString('base64')
    })

    const thumb = new Parse.File('image.jpg', {
      base64: imageThumbData.toString('base64')
    })

    await Promise.all([file.save(), thumb.save()])

    obj.set('image', file)
    obj.set('imageThumb', thumb)

  } else if (obj.dirty('image') && !obj.get('image')) {
    obj.set('imageThumb', null)
  }


})

提前感谢您的帮助!

nginx nginx-reverse-proxy parse-server
1个回答
0
投票

我认为问题出在 Parse.Cloud.httpRequest 函数中。 请求没有结束。

我将 followRedirect 选项放入但始终相同。

请问有什么想法吗?

© www.soinside.com 2019 - 2024. All rights reserved.