Adds ability to override mount with publicServerURL for production uses
This commit is contained in:
@@ -2,6 +2,7 @@ var request = require('request');
|
|||||||
var parseServerPackage = require('../package.json');
|
var parseServerPackage = require('../package.json');
|
||||||
var MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
|
var MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
|
||||||
var ParseServer = require("../src/index");
|
var ParseServer = require("../src/index");
|
||||||
|
var Config = require('../src/Config');
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
|
|
||||||
describe('server', () => {
|
describe('server', () => {
|
||||||
@@ -246,4 +247,37 @@ describe('server', () => {
|
|||||||
expect(ParseServer.FileSystemAdapter).toThrow();
|
expect(ParseServer.FileSystemAdapter).toThrow();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('properly gives publicServerURL when set', done => {
|
||||||
|
setServerConfiguration({
|
||||||
|
serverURL: 'http://localhost:8378/1',
|
||||||
|
appId: 'test',
|
||||||
|
masterKey: 'test',
|
||||||
|
publicServerURL: 'https://myserver.com/1'
|
||||||
|
});
|
||||||
|
var 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'
|
||||||
|
});
|
||||||
|
var config = new Config('test', 'http://localhost:8378/1/');
|
||||||
|
expect(config.mount).toEqual('http://localhost:8378/1');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw when getting invalid mount', done => {
|
||||||
|
expect(() => setServerConfiguration({
|
||||||
|
serverURL: 'http://localhost:8378/1',
|
||||||
|
appId: 'test',
|
||||||
|
masterKey: 'test',
|
||||||
|
publicServerURL: 'blabla:/some'
|
||||||
|
}) ).toThrow("publicServerURL should be a valid HTTPS URL starting with https://");
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,6 +4,16 @@
|
|||||||
|
|
||||||
import cache from './cache';
|
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 {
|
export class Config {
|
||||||
constructor(applicationId: string, mount: string) {
|
constructor(applicationId: string, mount: string) {
|
||||||
let DatabaseAdapter = require('./DatabaseAdapter');
|
let DatabaseAdapter = require('./DatabaseAdapter');
|
||||||
@@ -24,7 +34,7 @@ export class Config {
|
|||||||
this.database = DatabaseAdapter.getDatabaseConnection(applicationId, cacheInfo.collectionPrefix);
|
this.database = DatabaseAdapter.getDatabaseConnection(applicationId, cacheInfo.collectionPrefix);
|
||||||
|
|
||||||
this.serverURL = cacheInfo.serverURL;
|
this.serverURL = cacheInfo.serverURL;
|
||||||
this.publicServerURL = cacheInfo.publicServerURL;
|
this.publicServerURL = removeTrailingSlash(cacheInfo.publicServerURL);
|
||||||
this.verifyUserEmails = cacheInfo.verifyUserEmails;
|
this.verifyUserEmails = cacheInfo.verifyUserEmails;
|
||||||
this.appName = cacheInfo.appName;
|
this.appName = cacheInfo.appName;
|
||||||
|
|
||||||
@@ -35,7 +45,7 @@ export class Config {
|
|||||||
this.userController = cacheInfo.userController;
|
this.userController = cacheInfo.userController;
|
||||||
this.authDataManager = cacheInfo.authDataManager;
|
this.authDataManager = cacheInfo.authDataManager;
|
||||||
this.customPages = cacheInfo.customPages || {};
|
this.customPages = cacheInfo.customPages || {};
|
||||||
this.mount = mount;
|
this.mount = removeTrailingSlash(mount);
|
||||||
this.liveQueryController = cacheInfo.liveQueryController;
|
this.liveQueryController = cacheInfo.liveQueryController;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +53,11 @@ export class Config {
|
|||||||
this.validateEmailConfiguration({verifyUserEmails: options.verifyUserEmails,
|
this.validateEmailConfiguration({verifyUserEmails: options.verifyUserEmails,
|
||||||
appName: options.appName,
|
appName: options.appName,
|
||||||
publicServerURL: options.publicServerURL})
|
publicServerURL: options.publicServerURL})
|
||||||
|
if (options.publicServerURL) {
|
||||||
|
if (!options.publicServerURL.startsWith("http://") && !options.publicServerURL.startsWith("https://")) {
|
||||||
|
throw "publicServerURL should be a valid HTTPS URL starting with https://"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static validateEmailConfiguration({verifyUserEmails, appName, publicServerURL}) {
|
static validateEmailConfiguration({verifyUserEmails, appName, publicServerURL}) {
|
||||||
@@ -56,6 +71,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() {
|
get invalidLinkURL() {
|
||||||
return this.customPages.invalidLink || `${this.publicServerURL}/apps/invalid_link.html`;
|
return this.customPages.invalidLink || `${this.publicServerURL}/apps/invalid_link.html`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user