本地主机解析与android模拟器的集成

Muh*_*mar 1 java android android-emulator parse-platform parse-server

我正在尝试在我的本地主机上设置解析服务器并尝试连接到我的应用程序模拟器。

这是我的解析代码

// Example express application adding the parse-server module to expose Parse
// compatible API routes.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;

var databaseUri = process.env.DATABASE_URI;

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://abc:27017/parse',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'chat-test',
  masterKey: process.env.MASTER_KEY || 'chat-test', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337',  // Don't forget to change to https if needed
  facebookAppIds: 'abc' //FaceBook App ID Keys. Comma Separated.
});
// 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 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('I dream of being a web site.');
});

var port = process.env.PORT || 1337;
app.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});
Run Code Online (Sandbox Code Playgroud)

我在用

Parse.initialize(new Parse.Configuration.Builder(getBaseContext()).applicationId("chat-test").server("http:/localhost:1337/parse/").build());
Run Code Online (Sandbox Code Playgroud)

我从实时服务器上得到了这一切,只是替换为本地主机,但我无法让 android 连接到本地主机。它给了我 i/o 失败。

我怎样才能让我的 android 模拟器使用这个本地主机解析

Ric*_*and 5

Android 模拟器实际上是一个虚拟机,这意味着 localhost 是模拟器的内部 IP。您可以通过 ip 访问您的计算机10.0.2.2

这意味着您应该将 URL 更改为http://10.0.2.2:1337/parse/.

完整的代码行应该是:

Parse.initialize(new Parse.Configuration.Builder(getBaseContext()).applicationId("chat-test").server("http://10.0.2.2:1337/parse/").build());
Run Code Online (Sandbox Code Playgroud)

这是记录在这里