Skip to content

Commit b4d915b

Browse files
authored
Support direct access server option (#5550)
* Support direct access config test options * add test * fix test * fix definitions * improve docs * Update .travis.yml * Revert "Update .travis.yml" This reverts commit 407f138.
1 parent f15360c commit b4d915b

File tree

7 files changed

+34
-7
lines changed

7 files changed

+34
-7
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
lib
22
coverage
3-
3+
out

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ The client keys used with Parse are no longer necessary with Parse Server. If yo
245245
* `auth` - Used to configure support for [3rd party authentication](http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication).
246246
* `facebookAppIds` - An array of valid Facebook application IDs that users may authenticate with.
247247
* `mountPath` - Mount path for the server. Defaults to `/parse`.
248+
* `directAccess` - Replace HTTP Interface when using JS SDK in current node runtime. Defaults to false. Caution, this is an experimental feature that may not be appropriate for production.
248249
* `filesAdapter` - The default behavior (GridStore) can be changed by creating an adapter class (see [`FilesAdapter.js`](https://github.com/parse-community/parse-server/blob/master/src/Adapters/Files/FilesAdapter.js)).
249250
* `maxUploadSize` - Max file size for uploads. Defaults to 20 MB.
250251
* `loggerAdapter` - The default behavior/transport (File) can be changed by creating an adapter class (see [`LoggerAdapter.js`](https://github.com/parse-community/parse-server/blob/master/src/Adapters/Logger/LoggerAdapter.js)).

spec/index.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,16 @@ describe('server', () => {
498498
.catch(done.fail);
499499
});
500500

501+
it('should allow direct access', async () => {
502+
const RESTController = Parse.CoreManager.getRESTController();
503+
const spy = spyOn(Parse.CoreManager, 'setRESTController').and.callThrough();
504+
await reconfigureServer({
505+
directAccess: true,
506+
});
507+
expect(spy).toHaveBeenCalledTimes(1);
508+
Parse.CoreManager.setRESTController(RESTController);
509+
});
510+
501511
it('should load a middleware from string', done => {
502512
reconfigureServer({
503513
middleware: 'spec/support/CustomMiddleware',

src/Options/Definitions.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ module.exports.ParseServerOptions = {
148148
userSensitiveFields: {
149149
env: 'PARSE_SERVER_USER_SENSITIVE_FIELDS',
150150
help:
151-
'Personally identifiable information fields in the user table the should be removed for non-authorized users. **Deprecated** @see protectedFields',
151+
'Personally identifiable information fields in the user table the should be removed for non-authorized users. Deprecated @see protectedFields',
152152
action: parsers.arrayParser,
153153
default: ['email'],
154154
},
155155
protectedFields: {
156156
env: 'PARSE_SERVER_PROTECTED_FIELDS',
157157
help:
158-
'Personally identifiable information fields in the user table the should be removed for non-authorized users.',
158+
'Protected fields that should be treated with extra security when fetching details.',
159159
action: parsers.objectParser,
160-
default: { _User: { '*': ['email'] } },
160+
default: [],
161161
},
162162
enableAnonymousUsers: {
163163
env: 'PARSE_SERVER_ENABLE_ANON_USERS',
@@ -280,6 +280,13 @@ module.exports.ParseServerOptions = {
280280
action: parsers.numberParser('cacheMaxSize'),
281281
default: 10000,
282282
},
283+
directAccess: {
284+
env: 'PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS',
285+
help:
286+
'Replace HTTP Interface when using JS SDK in current node runtime, defaults to false. Caution, this is an experimental feature that may not be appropriate for production.',
287+
action: parsers.booleanParser,
288+
default: false,
289+
},
283290
enableSingleSchemaCache: {
284291
env: 'PARSE_SERVER_ENABLE_SINGLE_SCHEMA_CACHE',
285292
help:

src/Options/docs.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
* @property {String} webhookKey Key sent with outgoing webhook calls
2929
* @property {String} fileKey Key for your files
3030
* @property {Boolean} preserveFileName Enable (or disable) the addition of a unique hash to the file names
31-
* @property {String[]} userSensitiveFields Personally identifiable information fields in the user table the should be removed for non-authorized users.
31+
* @property {String[]} userSensitiveFields Personally identifiable information fields in the user table the should be removed for non-authorized users. Deprecated @see protectedFields
32+
* @property {Any} protectedFields Protected fields that should be treated with extra security when fetching details.
3233
* @property {Boolean} enableAnonymousUsers Enable (or disable) anon users, defaults to true
3334
* @property {Boolean} allowClientClassCreation Enable (or disable) client class creation, defaults to true
3435
* @property {Any} auth Configuration for your authentication providers, as stringified JSON. See http://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication
@@ -50,6 +51,7 @@
5051
* @property {Number} schemaCacheTTL The TTL for caching the schema for optimizing read/write operations. You should put a long TTL when your DB is in production. default to 5000; set 0 to disable.
5152
* @property {Number} cacheTTL Sets the TTL for the in memory cache (in ms), defaults to 5000 (5 seconds)
5253
* @property {Number} cacheMaxSize Sets the maximum size for the in memory cache, defaults to 10000
54+
* @property {Boolean} directAccess Replace HTTP Interface when using JS SDK in current node runtime, defaults to false. Caution, this is an experimental feature that may not be appropriate for production.
5355
* @property {Boolean} enableSingleSchemaCache Use a single schema cache shared across requests. Reduces number of queries made to _SCHEMA, defaults to false, i.e. unique schema cache per request.
5456
* @property {Boolean} enableExpressErrorHandler Enables the default express error handler for all errors
5557
* @property {Number} objectIdSize Sets the number of characters in generated object id's, default 10

src/Options/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ export interface ParseServerOptions {
145145
/* Sets the maximum size for the in memory cache, defaults to 10000
146146
:DEFAULT: 10000 */
147147
cacheMaxSize: ?number;
148+
/* Replace HTTP Interface when using JS SDK in current node runtime, defaults to false. Caution, this is an experimental feature that may not be appropriate for production.
149+
:ENV: PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS
150+
:DEFAULT: false */
151+
directAccess: ?boolean;
148152
/* Use a single schema cache shared across requests. Reduces number of queries made to _SCHEMA, defaults to false, i.e. unique schema cache per request.
149153
:DEFAULT: false */
150154
enableSingleSchemaCache: ?boolean;

src/ParseServer.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class ParseServer {
136136
* @static
137137
* Create an express app for the parse server
138138
* @param {Object} options let you specify the maxUploadSize when creating the express app */
139-
static app({ maxUploadSize = '20mb', appId }) {
139+
static app({ maxUploadSize = '20mb', appId, directAccess }) {
140140
// This app serves the Parse API directly.
141141
// It's the equivalent of https://api.parse.com/1 in the hosted Parse API.
142142
var api = express();
@@ -193,7 +193,10 @@ class ParseServer {
193193
ParseServer.verifyServerUrl();
194194
});
195195
}
196-
if (process.env.PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS === '1') {
196+
if (
197+
process.env.PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS === '1' ||
198+
directAccess
199+
) {
197200
Parse.CoreManager.setRESTController(
198201
ParseServerRESTController(appId, appRouter)
199202
);

0 commit comments

Comments
 (0)