Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 解析服务器-图像文件';路径返回本地主机_Mongodb_Azure_Parse Platform - Fatal编程技术网

Mongodb 解析服务器-图像文件';路径返回本地主机

Mongodb 解析服务器-图像文件';路径返回本地主机,mongodb,azure,parse-platform,Mongodb,Azure,Parse Platform,我在Azure上部署了2台Ubuntu服务器。首先,我安装了解析服务器,第二,我安装了MongoDB(我还通过mongorestore)从我以前的服务器上放置了一个就绪的db) 一切正常!解析服务器和MongoDB服务器。他们也能很好地沟通。问题是,当我运行我的iOS应用程序时,它正确地带来了所有数据,除了图像。我打印了一个图像的URL,下面是它返回的内容:http://localhost:1337/parse/files/filename.jpeg 如果我将localhost替换为服务器的ip

我在Azure上部署了2台Ubuntu服务器。首先,我安装了解析服务器,第二,我安装了MongoDB(我还通过
mongorestore
)从我以前的服务器上放置了一个就绪的db)

一切正常!解析服务器和MongoDB服务器。他们也能很好地沟通。问题是,当我运行我的iOS应用程序时,它正确地带来了所有数据,除了图像。我打印了一个图像的URL,下面是它返回的内容:
http://localhost:1337/parse/files/filename.jpeg

如果我将
localhost
替换为服务器的ip,则可以很好地获取图像

以下是我在
index.js上的内容:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var ParseDashboard = require('parse-dashboard');
var allowInsecureHTTP = true;
var path = require('path');

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://IP:27017/db',
  cloud: './cloud/main.js',
  appId: process.env.APP_ID || 'xxx',
  masterKey: process.env.MASTER_KEY || 'xxx', //Add your master key here. Keep it secret!
  fileKey: 'xxx',  
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',  // Don't forget to change to https if needed

  // Enable email verification
  verifyUserEmails: false,

  // The public URL of your app.
  // This will appear in the link that is used to verify email addresses and reset passwords.
  // Set the mount path as it is in serverURL
  publicServerURL: 'http://localhost:1337/parse',
});

// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

var app = express();

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
  res.status(200).send('Make sure to star the parse-server repo on GitHub!');
});

// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
  res.sendFile(path.join(__dirname, '/public/test.html'));
});

var port = process.env.PORT || 1337;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

// Set up parse dashboard
var config = {
  "allowInsecureHTTP": true,
  "apps": [
    {
      "serverURL": "http://localhost:1337/parse",
      "appId": "xxx",
      "masterKey": "xxx",
      "appName": "name",
      "production": true
    }
  ],
  "users": [
    {
      "user":"username",
      "pass":"pass"
    }
  ]
};

var dashboard = new ParseDashboard(config, config.allowInsecureHTTP);
var dashApp = express();

// make the Parse Dashboard available at /dashboard
dashApp.use('/dashboard', dashboard);  

// Parse Server plays nicely with the rest of your web routes
dashApp.get('/', function(req, res) {  
  res.status(200).send('Parse Dashboard App');
});

var httpServerDash = require('http').createServer(dashApp);  
httpServerDash.listen(4040, function() {  
    console.log('dashboard-server running on port 4040.');
});
我在Parse的文档中注意到的一点是:
在Parse上使用文件时,需要在Parse服务器配置中使用publicServerURL选项。这是访问文件的URL,因此它应该是解析到解析服务器的URL。确保在此URL中包含您的装载点。

问题是,本文档是在考虑MongoDB的情况下编写的,它与Parse位于同一台服务器上,而在我的例子中,不是


有什么想法吗?

我不得不从
http://localhost:1337/parse
http://publicIP:1337/parse
一切都很顺利

我不得不从
http://localhost:1337/parse
http://publicIP:1337/parse
一切都很顺利

如果您想使用文件(图像)下载它们,只需使用@Sotiris Kaniras提到的
publicServerURL

我想补充一点,
config.json
位于
~/stack/parse/config.json
中。这里还有
serverURL
publicServerURL

在我的例子中,我需要添加
publicServerURL
参数和
serverURL
,因为它还不存在。
因此,这两个参数(
publicServerURL
&
serverURL
)都是互补的,而不是互斥的,请同时使用它们。

如果您想使用文件(图像)下载它们,只需使用@Sotiris Kaniras提到的
publicServerURL

我想补充一点,
config.json
位于
~/stack/parse/config.json
中。这里还有
serverURL
publicServerURL

在我的例子中,我需要添加
publicServerURL
参数和
serverURL
,因为它还不存在。 因此,这两个参数(
publicServerURL
&
serverURL
)都是互补的,而不是互斥的,请同时使用它们