From 70425525079361421b3fd4c8505541850d54997f Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Mon, 5 Apr 2021 02:28:28 +0200 Subject: [PATCH] Enable direct access by default (#6636) * enabled direct access by default * removed obsolete direct access option test case * quick fix test * Set RESTController during tests * Properly handle RESTController * Documentation * revert changes * rerun tests * remove extra parse instance * Revert "remove extra parse instance" This reverts commit 21422f45f1548ebddddd1c4ccbc03a94b4994429. * Ensure restcontroller is set * Fix test * improved option docs * renamed direct access env var * added deprecations to README * added deprecation definition * fixed docs typo * improve promise rejection warning test * added renaming of env var to deprecation warning Co-authored-by: Diamond Lewis --- README.md | 9 +++++++++ spec/ParseServer.spec.js | 2 +- spec/helper.js | 3 +++ spec/index.spec.js | 2 +- src/Deprecator/Deprecations.js | 15 +++++++++++++-- src/Deprecator/Deprecator.js | 3 ++- src/Options/Definitions.js | 4 ++-- src/Options/docs.js | 2 +- src/Options/index.js | 7 +++++-- src/ParseServerRESTController.js | 3 ++- 10 files changed, 39 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8016b2d7..2e4ccfb9 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ The full documentation for Parse Server is available in the [wiki](https://githu - [Reserved Keys](#reserved-keys) - [Parameters](#parameters-1) - [Logging](#logging) +- [Deprecations](#deprecations) - [Live Query](#live-query) - [GraphQL](#graphql) - [Running](#running) @@ -754,6 +755,14 @@ Logs are also viewable in Parse Dashboard. **Want new line delimited JSON error logs (for consumption by CloudWatch, Google Cloud Logging, etc)?** Pass the `JSON_LOGS` environment variable when starting `parse-server`. Usage :- `JSON_LOGS='1' parse-server --appId APPLICATION_ID --masterKey MASTER_KEY` +# Deprecations + +The following Parse Server options and APIs are deprecated and will change in future versions. The "Deprecation" version indicates from when an item has been deprecated with runtime warnings. The "End-of-Life" version indicates when the deprecation period has ended and the breaking change came into effect. In rare cases, deprecations may be revoked without any breaking change coming into effect. + +| Type | Item | Deprecation | End-of-Life | Details | +|--------|----------------|-------------|-------------|-----------------------------------------| +| Option | `directAccess` | `5.0.0` | tbd | Default changes from `false` to `true`. | + # Live Query Live queries are meant to be used in real-time reactive applications, where just using the traditional query paradigm could cause several problems, like increased response time and high network and server usage. Live queries should be used in cases where you need to continuously update a page with fresh data coming from the database, which often happens in (but is not limited to) online games, messaging clients and shared to-do lists. diff --git a/spec/ParseServer.spec.js b/spec/ParseServer.spec.js index 904e0b16..fcb15f64 100644 --- a/spec/ParseServer.spec.js +++ b/spec/ParseServer.spec.js @@ -107,7 +107,7 @@ describe('Server Url Checks', () => { }); parseServerProcess.on('close', async code => { expect(code).toEqual(1); - expect(stdout).toBeUndefined(); + expect(stdout).not.toContain('UnhandledPromiseRejectionWarning'); expect(stderr).toContain('MongoServerSelectionError'); await reconfigureServer(); done(); diff --git a/spec/helper.js b/spec/helper.js index 8d9a23f1..44f87c43 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -38,6 +38,7 @@ const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/Postgre .default; const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageAdapter').default; const RedisCacheAdapter = require('../lib/Adapters/Cache/RedisCacheAdapter').default; +const RESTController = require('parse/lib/node/RESTController'); const { VolatileClassesSchemas } = require('../lib/Controllers/SchemaController'); const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase'; @@ -95,6 +96,7 @@ const defaultConfiguration = { masterKey: 'test', readOnlyMasterKey: 'read-only-test', fileKey: 'test', + directAccess: false, silent, logLevel, fileUpload: { @@ -156,6 +158,7 @@ const reconfigureServer = (changedConfiguration = {}) => { if (error) { reject(error); } else { + Parse.CoreManager.setRESTController(RESTController); resolve(parseServer); } }, diff --git a/spec/index.spec.js b/spec/index.spec.js index 5ab05bd2..d10fda17 100644 --- a/spec/index.spec.js +++ b/spec/index.spec.js @@ -512,7 +512,7 @@ describe('server', () => { await reconfigureServer({ directAccess: true, }); - expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledTimes(2); Parse.CoreManager.setRESTController(RESTController); }); diff --git a/src/Deprecator/Deprecations.js b/src/Deprecator/Deprecations.js index 5c7cc363..e32b305f 100644 --- a/src/Deprecator/Deprecations.js +++ b/src/Deprecator/Deprecations.js @@ -8,7 +8,18 @@ * or set to an empty string if the current key will be removed without replacement. * - `changeNewDefault`: Set the new default value if the key's default value * will change in a future version. + * - `solution`: The instruction to resolve this deprecation warning. Optional. This + * instruction must not include the deprecation warning which is auto-generated. + * It should only contain additional instruction regarding the deprecation if + * necessary. * - * If there are no deprecations this must return an empty array anyway. + * If there are no deprecations, this must return an empty array. */ -module.exports = []; +module.exports = [ + { + optionKey: 'directAccess', + changeNewDefault: 'true', + solution: + "Additionally, the environment variable 'PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS' will be deprecated and renamed to 'PARSE_SERVER_DIRECT_ACCESS' in a future version; it is currently possible to use either one.", + }, +]; diff --git a/src/Deprecator/Deprecator.js b/src/Deprecator/Deprecator.js index 53036fcb..5ab0bb43 100644 --- a/src/Deprecator/Deprecator.js +++ b/src/Deprecator/Deprecator.js @@ -16,12 +16,13 @@ class Deprecator { // Scan for deprecations for (const deprecation of Deprecator._getDeprecations()) { // Get deprecation properties + const solution = deprecation.solution; const optionKey = deprecation.optionKey; const changeNewDefault = deprecation.changeNewDefault; // If default will change, only throw a warning if option is not set if (changeNewDefault != null && options[optionKey] == null) { - Deprecator._log({ optionKey, changeNewDefault }); + Deprecator._log({ optionKey, changeNewDefault, solution }); } } } diff --git a/src/Options/Definitions.js b/src/Options/Definitions.js index 01bd2233..dff37662 100644 --- a/src/Options/Definitions.js +++ b/src/Options/Definitions.js @@ -110,9 +110,9 @@ module.exports.ParseServerOptions = { default: 'mongodb://localhost:27017/parse', }, directAccess: { - env: 'PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS', + env: 'PARSE_SERVER_DIRECT_ACCESS', help: - '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.', + 'Set to `true` if Parse requests within the same Node.js environment as Parse Server should be routed to Parse Server directly instead of via the HTTP interface. Default is `false`.

If set to `false` then Parse requests within the same Node.js environment as Parse Server are executed as HTTP requests sent to Parse Server via the `serverURL`. For example, a `Parse.Query` in Cloud Code is calling Parse Server via a HTTP request. The server is essentially making a HTTP request to itself, unnecessarily using network resources such as network ports.

\u26A0\uFE0F In environments where multiple Parse Server instances run behind a load balancer and Parse requests within the current Node.js environment should be routed via the load balancer and distributed as HTTP requests among all instances via the `serverURL`, this should be set to `false`.', action: parsers.booleanParser, default: false, }, diff --git a/src/Options/docs.js b/src/Options/docs.js index dccf436d..c58339f0 100644 --- a/src/Options/docs.js +++ b/src/Options/docs.js @@ -20,7 +20,7 @@ * @property {Adapter} databaseAdapter Adapter module for the database * @property {DatabaseOptions} databaseOptions Options to pass to the database client * @property {String} databaseURI The full URI to your database. Supported databases are mongodb or postgres. - * @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. + * @property {Boolean} directAccess Set to `true` if Parse requests within the same Node.js environment as Parse Server should be routed to Parse Server directly instead of via the HTTP interface. Default is `false`.

If set to `false` then Parse requests within the same Node.js environment as Parse Server are executed as HTTP requests sent to Parse Server via the `serverURL`. For example, a `Parse.Query` in Cloud Code is calling Parse Server via a HTTP request. The server is essentially making a HTTP request to itself, unnecessarily using network resources such as network ports.

⚠️ In environments where multiple Parse Server instances run behind a load balancer and Parse requests within the current Node.js environment should be routed via the load balancer and distributed as HTTP requests among all instances via the `serverURL`, this should be set to `false`. * @property {String} dotNetKey Key for Unity and .Net SDK * @property {Adapter} emailAdapter Adapter module for email sending * @property {Boolean} emailVerifyTokenReuseIfValid an existing email verify token should be reused when resend verification email is requested diff --git a/src/Options/index.js b/src/Options/index.js index b0c8993c..bd32855e 100644 --- a/src/Options/index.js +++ b/src/Options/index.js @@ -165,8 +165,11 @@ export interface ParseServerOptions { /* Sets the maximum size for the in memory cache, defaults to 10000 :DEFAULT: 10000 */ cacheMaxSize: ?number; - /* 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. - :ENV: PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS + /* Set to `true` if Parse requests within the same Node.js environment as Parse Server should be routed to Parse Server directly instead of via the HTTP interface. Default is `false`. +

+ If set to `false` then Parse requests within the same Node.js environment as Parse Server are executed as HTTP requests sent to Parse Server via the `serverURL`. For example, a `Parse.Query` in Cloud Code is calling Parse Server via a HTTP request. The server is essentially making a HTTP request to itself, unnecessarily using network resources such as network ports. +

+ ⚠️ In environments where multiple Parse Server instances run behind a load balancer and Parse requests within the current Node.js environment should be routed via the load balancer and distributed as HTTP requests among all instances via the `serverURL`, this should be set to `false`. :DEFAULT: false */ directAccess: ?boolean; /* Enables the default express error handler for all errors diff --git a/src/ParseServerRESTController.js b/src/ParseServerRESTController.js index 8293b94a..9e765ff3 100644 --- a/src/ParseServerRESTController.js +++ b/src/ParseServerRESTController.js @@ -119,7 +119,7 @@ function ParseServerRESTController(applicationId, router) { applicationId: applicationId, sessionToken: options.sessionToken, installationId: options.installationId, - context: options.context || {}, // Add context + context: options.context || {}, }, query, }; @@ -155,6 +155,7 @@ function ParseServerRESTController(applicationId, router) { return { request: handleRequest, ajax: RESTController.ajax, + handleError: RESTController.handleError, }; }