cnichs27
cnichs27

Reputation: 258

Uncaught SyntaxError: Unexpected token ILLEGAL in main.js:4

Using the command line to update Parse Cloud Code to the following. Getting this error for some reason. Getting uncaught syntax error:Unexpected ILLEGAL on line 4. Command line says finished uploading files, however, this error is printed immediately right below and parse cloud code is not updated.

// Use Parse.Cloud.define to define as many cloud functions as you want.
// For example:

Parse.Cloud.define("hello", function(request, response) {
     response.success(“Hello, PARSE Cloud coming back”);
});

var express = require("express"),
    app = express(),
    crypto = require('crypto'),
    buffer = require('buffer'),
    url = require('url');

var config = new Parse.Object("Config");
config.set("client_id", "");
config.set("client_secret", "");
config.set("callback_url", "");
config.set("endpoint", "");

var AUTH_HEADER = "Basic " + new buffer.Buffer(config.get("client_id")      + ":" + config.get("client_secret")).toString("base64");

app.use(express.bodyParser());

Parse.Cloud.define("swap", function (req, res) {
    if (!req.body || !req.body.hasOwnProperty("code")) {
        res.status(550).send("Permission Denied");
        return;
}

var form_data = {
    "grant_type": "authorization_code",
    "redirect_uri": config.get("callback_url"),
    "code": req.body.code
};

Parse.Cloud.httpRequest({
    method: "POST",
    url: url.resolve(config.get("endpoint"), "/api/token"),
    headers: {
        "Authorization": AUTH_HEADER,
        "Content-Type": "application/x-www-form-urlencoded"
    },
    body: form_data,
    success: function(httpResponse) {
        if (httpResponse.status != 200) {
            res.status(550).send("Permission Denied");
            return;
        }

        var token_data = JSON.parse(httpResponse.text);

        res.status(200).set({
            "Content-Type": "application/json"
        }).send(token_data);
    },
    error: function(httpResponse) {
        res.status(500).send("Internal Server Error");
        return;
    }
  });
});

Upvotes: 0

Views: 438

Answers (2)

Phiter
Phiter

Reputation: 14982

The quotes in the second line are not valid tokens, so the compiler doesn't understand them:

Parse.Cloud.define("hello", function(request, response) {
     response.success(“Hello, PARSE Cloud coming back”); //Those quotes.
});

Change the with the normal " and you're good to go!

Upvotes: 1

gegillam
gegillam

Reputation: 136

You're using an odd quote character.

http://screencast.com/t/ZAPBzvSgP

Upvotes: 1

Related Questions