Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Server running locally returns "Unable to connect to the Parse API" when calling User signUp #538

Closed
enjoyjeremy-bc opened this issue Feb 20, 2016 · 4 comments

Comments

@enjoyjeremy-bc
Copy link

Is there any reason I'm getting this error when running parse server locally, but not when hosted on Heroku? Status:100 Message:XMLHttpRequest failed: "Unable to connect to the Parse API"

I have mongodb installed and running locally. I also have a .env file that contains APP_ID and MASTER_KEY that gets pulled in with dotenv locally.

Here's an example of what I'm trying to do...

var express = require('express');
var bodyParser = require('body-parser');
var dotenv  = require('dotenv').config({silent: true});
var ParseServer = require('parse-server').ParseServer;
var Parse = require('parse/node');

// Set up the parse server
var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;
var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || ''
});

// Set up express
var app = express();
app.use(express.static(__dirname + '/public'));
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: true
}));

// Initialize parse so that I can use in my routes and controllers
Parse.initialize(process.env.APP_ID,'unused');
Parse.serverURL = process.env.SERVER_URI || 'http://locahost:1337/parse';

// Routes
app.get('/', function(req, res) {
  res.status(200).send('[form goes here that sends POST to "/sign-up"]');
});
app.post('/sign-up', function(req, res) {
  var user = new Parse.User();
  user.set("email", req.body.inputEmail);
  user.set("password", req.body.inputPassword);

  user.signUp(null, {
    success: function(user) {
      res.status(200).send('Signup Success!');
    },
    error: function(user, error) {
      res.status(200).send('Signup Failed');
    }
  });
});

var port = process.env.PORT || 1337;
app.listen(port);

(originally posted on stack overflow)
http://stackoverflow.com/questions/35475209/parse-server-running-locally-has-error-when-calling-user-signup

@drew-gross
Copy link
Contributor

You need to set your server's url in the configuration of your server.

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '',
  serverURL: process.env.SERVER_URI || 'http://localhost:1337/parse' // add this line
});

@enjoyjeremy-bc
Copy link
Author

Ah, thanks for catching that! That bonehead typo was part of the issue, but I also incorrectly assumed I needed to initialize the Parse SDK. Didn't realize that ParseServer takes care of that already.
See this answer on SO: http://stackoverflow.com/questions/35475209/parse-server-running-locally-has-error-when-calling-user-signup

@thibauddavid
Copy link

serverURL: process.env.SERVER_URI || 'http://locahost:1337/parse' // add this line

There is a l missing in localhost within @drew-gross 's answer in case other has error with this.

@drew-gross
Copy link
Contributor

Thanks, I've updated my comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants