Skip to content

Commit bae31ed

Browse files
mtrezzadplewis
authored andcommitted
Enable direct access by default (parse-community#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 24baffc commit bae31ed

10 files changed

+39
-11
lines changed

Diff for: README.md

+9
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.

Diff for: spec/ParseServer.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('Server Url Checks', () => {
100100
});
101101
parseServerProcess.on('close', code => {
102102
expect(code).toEqual(1);
103-
expect(stdout).toBeUndefined();
103+
expect(stdout).not.toContain('UnhandledPromiseRejectionWarning');
104104
expect(stderr).toContain('MongoServerSelectionError');
105105
done();
106106
});

Diff for: spec/helper.js

+3
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
},

Diff for: spec/index.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ describe('server', () => {
510510
await reconfigureServer({
511511
directAccess: true,
512512
});
513-
expect(spy).toHaveBeenCalledTimes(1);
513+
expect(spy).toHaveBeenCalledTimes(2);
514514
Parse.CoreManager.setRESTController(RESTController);
515515
});
516516

Diff for: src/Deprecator/Deprecations.js

+13-2
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+
];

Diff for: src/Deprecator/Deprecator.js

+2-1
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
}

Diff for: src/Options/Definitions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ module.exports.ParseServerOptions = {
116116
default: 'mongodb://localhost:27017/parse',
117117
},
118118
directAccess: {
119-
env: 'PARSE_SERVER_ENABLE_EXPERIMENTAL_DIRECT_ACCESS',
119+
env: 'PARSE_SERVER_DIRECT_ACCESS',
120120
help:
121-
'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.',
121+
'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`.',
122122
action: parsers.booleanParser,
123123
default: false,
124124
},

Diff for: src/Options/docs.js

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

Diff for: src/Options/index.js

+5-2
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

Diff for: src/ParseServerRESTController.js

+2-1
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)