Use the Postgres Adapter with a Postgres URI (#2871)
* Use the Postgres Adapter with a Postgres URI * Handle malformed databaseURI
This commit is contained in:
committed by
Florent Vilmart
parent
c253daa9c9
commit
7af320932a
@@ -7,6 +7,7 @@ var batch = require('./batch'),
|
|||||||
multer = require('multer'),
|
multer = require('multer'),
|
||||||
Parse = require('parse/node').Parse,
|
Parse = require('parse/node').Parse,
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
|
url = require('url'),
|
||||||
authDataManager = require('./authDataManager');
|
authDataManager = require('./authDataManager');
|
||||||
|
|
||||||
import defaults from './defaults';
|
import defaults from './defaults';
|
||||||
@@ -54,6 +55,7 @@ import DatabaseController from './Controllers/DatabaseController';
|
|||||||
import SchemaCache from './Controllers/SchemaCache';
|
import SchemaCache from './Controllers/SchemaCache';
|
||||||
import ParsePushAdapter from 'parse-server-push-adapter';
|
import ParsePushAdapter from 'parse-server-push-adapter';
|
||||||
import MongoStorageAdapter from './Adapters/Storage/Mongo/MongoStorageAdapter';
|
import MongoStorageAdapter from './Adapters/Storage/Mongo/MongoStorageAdapter';
|
||||||
|
import PostgresStorageAdapter from './Adapters/Storage/Postgres/PostgresStorageAdapter';
|
||||||
|
|
||||||
import { ParseServerRESTController } from './ParseServerRESTController';
|
import { ParseServerRESTController } from './ParseServerRESTController';
|
||||||
// Mutate the Parse object to add the Cloud Code handlers
|
// Mutate the Parse object to add the Cloud Code handlers
|
||||||
@@ -145,11 +147,7 @@ class ParseServer {
|
|||||||
if ((databaseOptions || (databaseURI && databaseURI != defaults.DefaultMongoURI) || collectionPrefix !== '') && databaseAdapter) {
|
if ((databaseOptions || (databaseURI && databaseURI != defaults.DefaultMongoURI) || collectionPrefix !== '') && databaseAdapter) {
|
||||||
throw 'You cannot specify both a databaseAdapter and a databaseURI/databaseOptions/collectionPrefix.';
|
throw 'You cannot specify both a databaseAdapter and a databaseURI/databaseOptions/collectionPrefix.';
|
||||||
} else if (!databaseAdapter) {
|
} else if (!databaseAdapter) {
|
||||||
databaseAdapter = new MongoStorageAdapter({
|
databaseAdapter = this.getDatabaseAdapter(databaseURI, collectionPrefix, databaseOptions)
|
||||||
uri: databaseURI,
|
|
||||||
collectionPrefix,
|
|
||||||
mongoOptions: databaseOptions,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
databaseAdapter = loadAdapter(databaseAdapter)
|
databaseAdapter = loadAdapter(databaseAdapter)
|
||||||
}
|
}
|
||||||
@@ -252,6 +250,27 @@ class ParseServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDatabaseAdapter(databaseURI, collectionPrefix, databaseOptions) {
|
||||||
|
let protocol;
|
||||||
|
try{
|
||||||
|
const parsedURI = url.parse(databaseURI);
|
||||||
|
protocol = parsedURI.protocol ? parsedURI.protocol.toLowerCase() : null;
|
||||||
|
}catch(e){}
|
||||||
|
switch (protocol) {
|
||||||
|
case 'postgres:':
|
||||||
|
return new PostgresStorageAdapter({
|
||||||
|
uri: databaseURI,
|
||||||
|
collectionPrefix
|
||||||
|
});
|
||||||
|
default:
|
||||||
|
return new MongoStorageAdapter({
|
||||||
|
uri: databaseURI,
|
||||||
|
collectionPrefix,
|
||||||
|
mongoOptions: databaseOptions,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get app() {
|
get app() {
|
||||||
return ParseServer.app(this.config);
|
return ParseServer.app(this.config);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user