Skip to content

Commit

Permalink
Adds ability to override mount with publicServerURL for production uses
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Mar 30, 2016
1 parent 7afc08a commit 34051bd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
24 changes: 24 additions & 0 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var request = require('request');
var parseServerPackage = require('../package.json');
var MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
var ParseServer = require("../src/index");
var Config = require('../src/Config');
var express = require('express');

describe('server', () => {
Expand Down Expand Up @@ -246,4 +247,27 @@ describe('server', () => {
expect(ParseServer.FileSystemAdapter).toThrow();
done();
});

it('properly gives publicServerURL when set', done => {
setServerConfiguration({
serverURL: 'http://localhost:8378/1',
appId: 'test',
masterKey: 'test',
publicServerURL: 'https://myserver.com/1'
});
let config = new Config('test', 'http://localhost:8378/1');
expect(config.mount).toEqual('https://myserver.com/1');
done();
});

it('properly removes trailing slash in mount', done => {
setServerConfiguration({
serverURL: 'http://localhost:8378/1',
appId: 'test',
masterKey: 'test'
});
let config = new Config('test', 'http://localhost:8378/1/');
expect(config.mount).toEqual('http://localhost:8378/1');
done();
});
});
26 changes: 24 additions & 2 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

import cache from './cache';

function removeTrailingSlash(str) {
if (!str) {
return str;
}
if (str.endsWith("/")) {
str = str.substr(0, str.length-1);
}
return str;
}

export class Config {
constructor(applicationId: string, mount: string) {
let DatabaseAdapter = require('./DatabaseAdapter');
Expand All @@ -24,7 +34,7 @@ export class Config {
this.database = DatabaseAdapter.getDatabaseConnection(applicationId, cacheInfo.collectionPrefix);

this.serverURL = cacheInfo.serverURL;
this.publicServerURL = cacheInfo.publicServerURL;
this.publicServerURL = removeTrailingSlash(cacheInfo.publicServerURL);
this.verifyUserEmails = cacheInfo.verifyUserEmails;
this.appName = cacheInfo.appName;

Expand All @@ -35,7 +45,7 @@ export class Config {
this.userController = cacheInfo.userController;
this.authDataManager = cacheInfo.authDataManager;
this.customPages = cacheInfo.customPages || {};
this.mount = mount;
this.mount = removeTrailingSlash(mount);
this.liveQueryController = cacheInfo.liveQueryController;
}

Expand All @@ -56,6 +66,18 @@ export class Config {
}
}

get mount() {
var mount = this._mount;
if (this.publicServerURL) {
mount = this.publicServerURL;
}
return mount;
}

set mount(newValue) {
this._mount = newValue;
}

get invalidLinkURL() {
return this.customPages.invalidLink || `${this.publicServerURL}/apps/invalid_link.html`;
}
Expand Down

0 comments on commit 34051bd

Please sign in to comment.