Skip to content

Commit 7042552

Browse files
mtrezzadplewis
andauthored
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 21422f4. * 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 <[email protected]>
1 parent 70e1347 commit 7042552

10 files changed

+39
-11
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ The full documentation for Parse Server is available in the [wiki](https://githu
7575
- [Reserved Keys](#reserved-keys)
7676
- [Parameters](#parameters-1)
7777
- [Logging](#logging)
78+
- [Deprecations](#deprecations)
7879
- [Live Query](#live-query)
7980
- [GraphQL](#graphql)
8081
- [Running](#running)
@@ -754,6 +755,14 @@ Logs are also viewable in Parse Dashboard.
754755
755756
**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`
756757
758+
# Deprecations
759+
760+
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.
761+
762+
| Type | Item | Deprecation | End-of-Life | Details |
763+
|--------|----------------|-------------|-------------|-----------------------------------------|
764+
| Option | `directAccess` | `5.0.0` | tbd | Default changes from `false` to `true`. |
765+
757766
# Live Query
758767
759768
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.

spec/ParseServer.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('Server Url Checks', () => {
107107
});
108108
parseServerProcess.on('close', async code => {
109109
expect(code).toEqual(1);
110-
expect(stdout).toBeUndefined();
110+
expect(stdout).not.toContain('UnhandledPromiseRejectionWarning');
111111
expect(stderr).toContain('MongoServerSelectionError');
112112
await reconfigureServer();
113113
done();

spec/helper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/Postgre
3838
.default;
3939
const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageAdapter').default;
4040
const RedisCacheAdapter = require('../lib/Adapters/Cache/RedisCacheAdapter').default;
41+
const RESTController = require('parse/lib/node/RESTController');
4142
const { VolatileClassesSchemas } = require('../lib/Controllers/SchemaController');
4243

4344
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
@@ -95,6 +96,7 @@ const defaultConfiguration = {
9596
masterKey: 'test',
9697
readOnlyMasterKey: 'read-only-test',
9798
fileKey: 'test',
99+
directAccess: false,
98100
silent,
99101
logLevel,
100102
fileUpload: {
@@ -156,6 +158,7 @@ const reconfigureServer = (changedConfiguration = {}) => {
156158
if (error) {
157159
reject(error);
158160
} else {
161+
Parse.CoreManager.setRESTController(RESTController);
159162
resolve(parseServer);
160163
}
161164
},

spec/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ describe('server', () => {
512512
await reconfigureServer({
513513
directAccess: true,
514514
});
515-
expect(spy).toHaveBeenCalledTimes(1);
515+
expect(spy).toHaveBeenCalledTimes(2);
516516
Parse.CoreManager.setRESTController(RESTController);
517517
});
518518

src/Deprecator/Deprecations.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88
* or set to an empty string if the current key will be removed without replacement.
99
* - `changeNewDefault`: Set the new default value if the key's default value
1010
* will change in a future version.
11+
* - `solution`: The instruction to resolve this deprecation warning. Optional. This
12+
* instruction must not include the deprecation warning which is auto-generated.
13+
* It should only contain additional instruction regarding the deprecation if
14+
* necessary.
1115
*
12-
* If there are no deprecations this must return an empty array anyway.
16+
* If there are no deprecations, this must return an empty array.
1317
*/
14-
module.exports = [];
18+
module.exports = [
19+
{
20+
optionKey: 'directAccess',
21+
changeNewDefault: 'true',
22+
solution:
23+
"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.",
24+
},
25+
];

src/Deprecator/Deprecator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ class Deprecator {
1616
// Scan for deprecations
1717
for (const deprecation of Deprecator._getDeprecations()) {
1818
// Get deprecation properties
19+
const solution = deprecation.solution;
1920
const optionKey = deprecation.optionKey;
2021
const changeNewDefault = deprecation.changeNewDefault;
2122

2223
// If default will change, only throw a warning if option is not set
2324
if (changeNewDefault != null && options[optionKey] == null) {
24-
Deprecator._log({ optionKey, changeNewDefault });
25+
Deprecator._log({ optionKey, changeNewDefault, solution });
2526
}
2627
}
2728
}

src/Options/Definitions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ module.exports.ParseServerOptions = {
110110
default: 'mongodb://localhost:27017/parse',
111111
},
112112
directAccess: {
113-
env: 'PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS',
113+
env: 'PARSE_SERVER_DIRECT_ACCESS',
114114
help:
115-
'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.',
115+
'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`.<br><br>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.<br><br>\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`.',
116116
action: parsers.booleanParser,
117117
default: false,
118118
},

src/Options/docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @property {Adapter<StorageAdapter>} databaseAdapter Adapter module for the database
2121
* @property {DatabaseOptions} databaseOptions Options to pass to the database client
2222
* @property {String} databaseURI The full URI to your database. Supported databases are mongodb or postgres.
23-
* @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.
23+
* @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`.<br><br>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.<br><br>⚠️ 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`.
2424
* @property {String} dotNetKey Key for Unity and .Net SDK
2525
* @property {Adapter<MailAdapter>} emailAdapter Adapter module for email sending
2626
* @property {Boolean} emailVerifyTokenReuseIfValid an existing email verify token should be reused when resend verification email is requested

src/Options/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,11 @@ export interface ParseServerOptions {
165165
/* Sets the maximum size for the in memory cache, defaults to 10000
166166
:DEFAULT: 10000 */
167167
cacheMaxSize: ?number;
168-
/* 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.
169-
:ENV: PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS
168+
/* 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`.
169+
<br><br>
170+
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.
171+
<br><br>
172+
⚠️ 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`.
170173
:DEFAULT: false */
171174
directAccess: ?boolean;
172175
/* Enables the default express error handler for all errors

src/ParseServerRESTController.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function ParseServerRESTController(applicationId, router) {
119119
applicationId: applicationId,
120120
sessionToken: options.sessionToken,
121121
installationId: options.installationId,
122-
context: options.context || {}, // Add context
122+
context: options.context || {},
123123
},
124124
query,
125125
};
@@ -155,6 +155,7 @@ function ParseServerRESTController(applicationId, router) {
155155
return {
156156
request: handleRequest,
157157
ajax: RESTController.ajax,
158+
handleError: RESTController.handleError,
158159
};
159160
}
160161

0 commit comments

Comments
 (0)