解析服务器 - 图像文件的路径 returns localhost
Parse Server - Image files' path returns localhost
我在 Azure 上部署了 2 台 Ubuntu 服务器。首先,我安装了 Parse Server,其次,我安装了 MongoDB。 (我还通过 mongorestore
从我以前的服务器那里放了一个现成的数据库)
一切正常!解析服务器和 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 的文档中注意到的一件事是:When using files on Parse, you will need to use the publicServerURL option in your Parse Server config. This is the URL that files will be accessed from, so it should be a URL that resolves to your Parse Server. Make sure to include your mount point in this URL.
问题在于,编写此文档时考虑到了 MongoDB,它与 Parse 在同一台服务器上,但在我的情况下不是。
有什么想法吗?
我不得不更换解析服务器配置的 publicServerURL
,从 http://localhost:1337/parse
到 http://publicIP:1337/parse
,一切都很顺利!
如果你想使用文件(图像)下载它们,只需使用publicServerURL
@Sotiris Kaniras
我要补充一点 config.json
在 ~/stack/parse/config.json
中。这也是 serverURL
和 publicServerURL
之间的区别
Difference between serverURL and publicServerURL on ParseServer
在我的例子中,我需要在 serverURL
旁边添加 publicServerURL
参数,因为它还不存在。
所以两个参数(publicServerURL
& serverURL
)是互补的,不互斥,两者都用。
我在 Azure 上部署了 2 台 Ubuntu 服务器。首先,我安装了 Parse Server,其次,我安装了 MongoDB。 (我还通过 mongorestore
从我以前的服务器那里放了一个现成的数据库)
一切正常!解析服务器和 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 的文档中注意到的一件事是:When using files on Parse, you will need to use the publicServerURL option in your Parse Server config. This is the URL that files will be accessed from, so it should be a URL that resolves to your Parse Server. Make sure to include your mount point in this URL.
问题在于,编写此文档时考虑到了 MongoDB,它与 Parse 在同一台服务器上,但在我的情况下不是。
有什么想法吗?
我不得不更换解析服务器配置的 publicServerURL
,从 http://localhost:1337/parse
到 http://publicIP:1337/parse
,一切都很顺利!
如果你想使用文件(图像)下载它们,只需使用publicServerURL
@Sotiris Kaniras
我要补充一点 config.json
在 ~/stack/parse/config.json
中。这也是 serverURL
和 publicServerURL
Difference between serverURL and publicServerURL on ParseServer
在我的例子中,我需要在 serverURL
旁边添加 publicServerURL
参数,因为它还不存在。
所以两个参数(publicServerURL
& serverURL
)是互补的,不互斥,两者都用。