Skip to content

Commit acc23d0

Browse files
airdrummingfoolflovilmart
authored andcommitted
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.
1 parent f99b558 commit acc23d0

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

spec/helper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var ParseServer = require('../src/index').ParseServer;
1010
var path = require('path');
1111

1212
var databaseURI = process.env.DATABASE_URI;
13-
var cloudMain = process.env.CLOUD_CODE_MAIN || '../spec/cloud/main.js';
13+
var cloudMain = process.env.CLOUD_CODE_MAIN || './spec/cloud/main.js';
1414
var port = 8378;
1515

1616
// Default server configuration for tests.

spec/index.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,26 @@ describe('server', () => {
175175
})
176176
});
177177

178+
it('can load absolute cloud code file', done => {
179+
setServerConfiguration({
180+
serverURL: 'http://localhost:8378/1',
181+
appId: 'test',
182+
masterKey: 'test',
183+
cloud: __dirname + '/cloud/main.js'
184+
});
185+
done();
186+
});
187+
188+
it('can load relative cloud code file', done => {
189+
setServerConfiguration({
190+
serverURL: 'http://localhost:8378/1',
191+
appId: 'test',
192+
masterKey: 'test',
193+
cloud: './spec/cloud/main.js'
194+
});
195+
done();
196+
});
197+
178198
it('can create a parse-server', done => {
179199
var parseServer = new ParseServer.default({
180200
appId: "aTestApp",

src/ParseServer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var batch = require('./batch'),
99
middlewares = require('./middlewares'),
1010
multer = require('multer'),
1111
Parse = require('parse/node').Parse,
12+
path = require('path'),
1213
authDataManager = require('./authDataManager');
1314

1415
import { logger,
@@ -142,7 +143,7 @@ class ParseServer {
142143
if (typeof cloud === 'function') {
143144
cloud(Parse)
144145
} else if (typeof cloud === 'string') {
145-
require(cloud);
146+
require(path.resolve(process.cwd(), cloud));
146147
} else {
147148
throw "argument 'cloud' must either be a string or a function";
148149
}

0 commit comments

Comments
 (0)