From acc23d082828b624bcdb746d36a06c80b5d117f0 Mon Sep 17 00:00:00 2001 From: Tommy Goode Date: Mon, 4 Apr 2016 07:43:06 -0500 Subject: [PATCH] Fix for #1334: using relative cloud code files broken * Adding tests for absolute and relative cloud code file loading. * Fixes #1334 by resolving relative cloud code file paths to the process' working directory. --- spec/helper.js | 2 +- spec/index.spec.js | 20 ++++++++++++++++++++ src/ParseServer.js | 3 ++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/spec/helper.js b/spec/helper.js index e8cabbb4ea..c134f339ab 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -10,7 +10,7 @@ var ParseServer = require('../src/index').ParseServer; var path = require('path'); var databaseURI = process.env.DATABASE_URI; -var cloudMain = process.env.CLOUD_CODE_MAIN || '../spec/cloud/main.js'; +var cloudMain = process.env.CLOUD_CODE_MAIN || './spec/cloud/main.js'; var port = 8378; // Default server configuration for tests. diff --git a/spec/index.spec.js b/spec/index.spec.js index b58cb2f2a6..c71d92675f 100644 --- a/spec/index.spec.js +++ b/spec/index.spec.js @@ -175,6 +175,26 @@ describe('server', () => { }) }); + it('can load absolute cloud code file', done => { + setServerConfiguration({ + serverURL: 'http://localhost:8378/1', + appId: 'test', + masterKey: 'test', + cloud: __dirname + '/cloud/main.js' + }); + done(); + }); + + it('can load relative cloud code file', done => { + setServerConfiguration({ + serverURL: 'http://localhost:8378/1', + appId: 'test', + masterKey: 'test', + cloud: './spec/cloud/main.js' + }); + done(); + }); + it('can create a parse-server', done => { var parseServer = new ParseServer.default({ appId: "aTestApp", diff --git a/src/ParseServer.js b/src/ParseServer.js index 6a35bd2a81..51f94dc044 100644 --- a/src/ParseServer.js +++ b/src/ParseServer.js @@ -9,6 +9,7 @@ var batch = require('./batch'), middlewares = require('./middlewares'), multer = require('multer'), Parse = require('parse/node').Parse, + path = require('path'), authDataManager = require('./authDataManager'); import { logger, @@ -142,7 +143,7 @@ class ParseServer { if (typeof cloud === 'function') { cloud(Parse) } else if (typeof cloud === 'string') { - require(cloud); + require(path.resolve(process.cwd(), cloud)); } else { throw "argument 'cloud' must either be a string or a function"; }