Skip to content

Commit

Permalink
Fix for #1334: using relative cloud code files broken
Browse files Browse the repository at this point in the history
* Adding tests for absolute and relative cloud code file loading.

* Fixes #1334 by resolving relative cloud code file paths to the process' working directory.
  • Loading branch information
airdrummingfool authored and flovilmart committed Apr 4, 2016
1 parent f99b558 commit acc23d0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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";
}
Expand Down

0 comments on commit acc23d0

Please sign in to comment.