Skip to content

Commit 34051bd

Browse files
committed
Adds ability to override mount with publicServerURL for production uses
1 parent 7afc08a commit 34051bd

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

spec/index.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var request = require('request');
22
var parseServerPackage = require('../package.json');
33
var MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
44
var ParseServer = require("../src/index");
5+
var Config = require('../src/Config');
56
var express = require('express');
67

78
describe('server', () => {
@@ -246,4 +247,27 @@ describe('server', () => {
246247
expect(ParseServer.FileSystemAdapter).toThrow();
247248
done();
248249
});
250+
251+
it('properly gives publicServerURL when set', done => {
252+
setServerConfiguration({
253+
serverURL: 'http://localhost:8378/1',
254+
appId: 'test',
255+
masterKey: 'test',
256+
publicServerURL: 'https://myserver.com/1'
257+
});
258+
let config = new Config('test', 'http://localhost:8378/1');
259+
expect(config.mount).toEqual('https://myserver.com/1');
260+
done();
261+
});
262+
263+
it('properly removes trailing slash in mount', done => {
264+
setServerConfiguration({
265+
serverURL: 'http://localhost:8378/1',
266+
appId: 'test',
267+
masterKey: 'test'
268+
});
269+
let config = new Config('test', 'http://localhost:8378/1/');
270+
expect(config.mount).toEqual('http://localhost:8378/1');
271+
done();
272+
});
249273
});

src/Config.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
import cache from './cache';
66

7+
function removeTrailingSlash(str) {
8+
if (!str) {
9+
return str;
10+
}
11+
if (str.endsWith("/")) {
12+
str = str.substr(0, str.length-1);
13+
}
14+
return str;
15+
}
16+
717
export class Config {
818
constructor(applicationId: string, mount: string) {
919
let DatabaseAdapter = require('./DatabaseAdapter');
@@ -24,7 +34,7 @@ export class Config {
2434
this.database = DatabaseAdapter.getDatabaseConnection(applicationId, cacheInfo.collectionPrefix);
2535

2636
this.serverURL = cacheInfo.serverURL;
27-
this.publicServerURL = cacheInfo.publicServerURL;
37+
this.publicServerURL = removeTrailingSlash(cacheInfo.publicServerURL);
2838
this.verifyUserEmails = cacheInfo.verifyUserEmails;
2939
this.appName = cacheInfo.appName;
3040

@@ -35,7 +45,7 @@ export class Config {
3545
this.userController = cacheInfo.userController;
3646
this.authDataManager = cacheInfo.authDataManager;
3747
this.customPages = cacheInfo.customPages || {};
38-
this.mount = mount;
48+
this.mount = removeTrailingSlash(mount);
3949
this.liveQueryController = cacheInfo.liveQueryController;
4050
}
4151

@@ -56,6 +66,18 @@ export class Config {
5666
}
5767
}
5868

69+
get mount() {
70+
var mount = this._mount;
71+
if (this.publicServerURL) {
72+
mount = this.publicServerURL;
73+
}
74+
return mount;
75+
}
76+
77+
set mount(newValue) {
78+
this._mount = newValue;
79+
}
80+
5981
get invalidLinkURL() {
6082
return this.customPages.invalidLink || `${this.publicServerURL}/apps/invalid_link.html`;
6183
}

0 commit comments

Comments
 (0)