Skip to content

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

Closed
@enjoyjeremy-bc

Description

@enjoyjeremy-bc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions