feat: Deprecate PublicAPIRouter in favor of PagesRouter (#9526)

This commit is contained in:
Daniel
2025-01-12 11:59:40 +11:00
committed by GitHub
parent 85b71dac09
commit 7f666292e8
6 changed files with 23 additions and 19 deletions

View File

@@ -14,6 +14,7 @@ The following is a list of deprecations, according to the [Deprecation Policy](h
| DEPPS8 | Login with expired 3rd party authentication token defaults to `false` | [#7079](https://github.com/parse-community/parse-server/pull/7079) | 5.3.0 (2022) | 7.0.0 (2024) | removed | - | | DEPPS8 | Login with expired 3rd party authentication token defaults to `false` | [#7079](https://github.com/parse-community/parse-server/pull/7079) | 5.3.0 (2022) | 7.0.0 (2024) | removed | - |
| DEPPS9 | Rename LiveQuery `fields` option to `keys` | [#8389](https://github.com/parse-community/parse-server/issues/8389) | 6.0.0 (2023) | 7.0.0 (2024) | removed | - | | DEPPS9 | Rename LiveQuery `fields` option to `keys` | [#8389](https://github.com/parse-community/parse-server/issues/8389) | 6.0.0 (2023) | 7.0.0 (2024) | removed | - |
| DEPPS10 | Config option `encodeParseObjectInCloudFunction` defaults to `true` | [#8634](https://github.com/parse-community/parse-server/issues/8634) | 6.2.0 (2023) | 8.0.0 (2025) | deprecated | - | | DEPPS10 | Config option `encodeParseObjectInCloudFunction` defaults to `true` | [#8634](https://github.com/parse-community/parse-server/issues/8634) | 6.2.0 (2023) | 8.0.0 (2025) | deprecated | - |
| DEPPS11 | Replace `PublicAPIRouter` with `PagesRouter` | [#7625](https://github.com/parse-community/parse-server/issues/7625) | 8.0.0 (2025) | 9.0.0 (2026) | deprecated | - |
[i_deprecation]: ## "The version and date of the deprecation." [i_deprecation]: ## "The version and date of the deprecation."
[i_removal]: ## "The version and date of the planned removal." [i_removal]: ## "The version and date of the planned removal."

View File

@@ -437,8 +437,6 @@ const server = ParseServer({
## Custom Routes ## Custom Routes
**Caution, this is an experimental feature that may not be appropriate for production.**
Custom routes allow to build user flows with webpages, similar to the existing password reset and email verification features. Custom routes are defined with the `pages` option in the Parse Server configuration: Custom routes allow to build user flows with webpages, similar to the existing password reset and email verification features. Custom routes are defined with the `pages` option in the Parse Server configuration:
### Example ### Example
@@ -448,7 +446,7 @@ const api = new ParseServer({
...otherOptions, ...otherOptions,
pages: { pages: {
enableRouter: true, // Enables the experimental feature; required for custom routes enableRouter: true,
customRoutes: [{ customRoutes: [{
method: 'GET', method: 'GET',
path: 'custom_route', path: 'custom_route',
@@ -485,7 +483,7 @@ The following paths are already used by Parse Server's built-in features and are
| Parameter | Optional | Type | Default value | Example values | Environment variable | Description | | Parameter | Optional | Type | Default value | Example values | Environment variable | Description |
|------------------------------|----------|-----------------|---------------|-----------------------|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |------------------------------|----------|-----------------|---------------|-----------------------|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `pages` | yes | `Object` | `undefined` | - | `PARSE_SERVER_PAGES` | The options for pages such as password reset and email verification. | | `pages` | yes | `Object` | `undefined` | - | `PARSE_SERVER_PAGES` | The options for pages such as password reset and email verification. |
| `pages.enableRouter` | yes | `Boolean` | `false` | - | `PARSE_SERVER_PAGES_ENABLE_ROUTER` | Is `true` if the pages router should be enabled; this is required for any of the pages options to take effect. **Caution, this is an experimental feature that may not be appropriate for production.** | | `pages.enableRouter` | yes | `Boolean` | `false` | - | `PARSE_SERVER_PAGES_ENABLE_ROUTER` | Is `true` if the pages router should be enabled; this is required for any of the pages options to take effect. |
| `pages.customRoutes` | yes | `Array` | `[]` | - | `PARSE_SERVER_PAGES_CUSTOM_ROUTES` | The custom routes. The routes are added in the order they are defined here, which has to be considered since requests traverse routes in an ordered manner. Custom routes are traversed after build-in routes such as password reset and email verification. | | `pages.customRoutes` | yes | `Array` | `[]` | - | `PARSE_SERVER_PAGES_CUSTOM_ROUTES` | The custom routes. The routes are added in the order they are defined here, which has to be considered since requests traverse routes in an ordered manner. Custom routes are traversed after build-in routes such as password reset and email verification. |
| `pages.customRoutes.method` | | `String` | - | `GET`, `POST` | - | The HTTP method of the custom route. | | `pages.customRoutes.method` | | `String` | - | `GET`, `POST` | - | The HTTP method of the custom route. |
| `pages.customRoutes.path` | | `String` | - | `custom_page` | - | The path of the custom route. Note that the same path can used if the `method` is different, for example a path `custom_page` can have two routes, a `GET` and `POST` route, which will be invoked depending on the HTTP request method. | | `pages.customRoutes.path` | | `String` | - | `custom_page` | - | The path of the custom route. Note that the same path can used if the `method` is different, for example a path `custom_page` can have two routes, a `GET` and `POST` route, which will be invoked depending on the HTTP request method. |
@@ -608,8 +606,6 @@ Assuming the script above is named, `parse_idempotency_delete_expired_records.sh
### Pages ### Pages
**Caution, this is an experimental feature that may not be appropriate for production.**
Custom pages as well as feature pages (e.g. password reset, email verification) can be localized with the `pages` option in the Parse Server configuration: Custom pages as well as feature pages (e.g. password reset, email verification) can be localized with the `pages` option in the Parse Server configuration:
```js ```js
@@ -617,7 +613,7 @@ const api = new ParseServer({
...otherOptions, ...otherOptions,
pages: { pages: {
enableRouter: true, // Enables the experimental feature; required for localization enableRouter: true,
enableLocalization: true, enableLocalization: true,
} }
} }
@@ -665,7 +661,7 @@ const api = new ParseServer({
...otherOptions, ...otherOptions,
pages: { pages: {
enableRouter: true, // Enables the experimental feature; required for localization enableRouter: true,
enableLocalization: true, enableLocalization: true,
customUrls: { customUrls: {
passwordReset: 'https://example.com/page.html' passwordReset: 'https://example.com/page.html'
@@ -722,7 +718,7 @@ const api = new ParseServer({
...otherOptions, ...otherOptions,
pages: { pages: {
enableRouter: true, // Enables the experimental feature; required for localization enableRouter: true,
enableLocalization: true, enableLocalization: true,
localizationJsonPath: './private/localization.json', localizationJsonPath: './private/localization.json',
localizationFallbackLocale: 'en' localizationFallbackLocale: 'en'
@@ -747,7 +743,7 @@ const api = new ParseServer({
...otherOptions, ...otherOptions,
pages: { pages: {
enableRouter: true, // Enables the experimental feature; required for localization enableRouter: true,
placeholders: { placeholders: {
exampleKey: 'exampleValue' exampleKey: 'exampleValue'
} }
@@ -761,7 +757,7 @@ const api = new ParseServer({
...otherOptions, ...otherOptions,
pages: { pages: {
enableRouter: true, // Enables the experimental feature; required for localization enableRouter: true,
placeholders: async (params) => { placeholders: async (params) => {
const value = await doSomething(params.locale); const value = await doSomething(params.locale);
return { return {
@@ -781,7 +777,7 @@ The following parameter and placeholder keys are reserved because they are used
| Parameter | Optional | Type | Default value | Example values | Environment variable | Description | | Parameter | Optional | Type | Default value | Example values | Environment variable | Description |
|-------------------------------------------------|----------|---------------------------------------|----------------------------------------|------------------------------------------------------|-----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |-------------------------------------------------|----------|---------------------------------------|----------------------------------------|------------------------------------------------------|-----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `pages` | yes | `Object` | `undefined` | - | `PARSE_SERVER_PAGES` | The options for pages such as password reset and email verification. | | `pages` | yes | `Object` | `undefined` | - | `PARSE_SERVER_PAGES` | The options for pages such as password reset and email verification. |
| `pages.enableRouter` | yes | `Boolean` | `false` | - | `PARSE_SERVER_PAGES_ENABLE_ROUTER` | Is `true` if the pages router should be enabled; this is required for any of the pages options to take effect. **Caution, this is an experimental feature that may not be appropriate for production.** | | `pages.enableRouter` | yes | `Boolean` | `false` | - | `PARSE_SERVER_PAGES_ENABLE_ROUTER` | Is `true` if the pages router should be enabled; this is required for any of the pages options to take effect. |
| `pages.enableLocalization` | yes | `Boolean` | `false` | - | `PARSE_SERVER_PAGES_ENABLE_LOCALIZATION` | Is true if pages should be localized; this has no effect on custom page redirects. | | `pages.enableLocalization` | yes | `Boolean` | `false` | - | `PARSE_SERVER_PAGES_ENABLE_LOCALIZATION` | Is true if pages should be localized; this has no effect on custom page redirects. |
| `pages.localizationJsonPath` | yes | `String` | `undefined` | `./private/translations.json` | `PARSE_SERVER_PAGES_LOCALIZATION_JSON_PATH` | The path to the JSON file for localization; the translations will be used to fill template placeholders according to the locale. | | `pages.localizationJsonPath` | yes | `String` | `undefined` | `./private/translations.json` | `PARSE_SERVER_PAGES_LOCALIZATION_JSON_PATH` | The path to the JSON file for localization; the translations will be used to fill template placeholders according to the locale. |
| `pages.localizationFallbackLocale` | yes | `String` | `en` | `en`, `en-GB`, `default` | `PARSE_SERVER_PAGES_LOCALIZATION_FALLBACK_LOCALE` | The fallback locale for localization if no matching translation is provided for the given locale. This is only relevant when providing translation resources via JSON file. | | `pages.localizationFallbackLocale` | yes | `String` | `en` | `en`, `en-GB`, `default` | `PARSE_SERVER_PAGES_LOCALIZATION_FALLBACK_LOCALE` | The fallback locale for localization if no matching translation is provided for the given locale. This is only relevant when providing translation resources via JSON file. |

View File

@@ -414,8 +414,7 @@ module.exports.ParseServerOptions = {
}, },
pages: { pages: {
env: 'PARSE_SERVER_PAGES', env: 'PARSE_SERVER_PAGES',
help: help: 'The options for pages such as password reset and email verification.',
'The options for pages such as password reset and email verification. Caution, this is an experimental feature that may not be appropriate for production.',
action: parsers.objectParser, action: parsers.objectParser,
type: 'PagesOptions', type: 'PagesOptions',
default: {}, default: {},
@@ -698,7 +697,7 @@ module.exports.PagesOptions = {
enableRouter: { enableRouter: {
env: 'PARSE_SERVER_PAGES_ENABLE_ROUTER', env: 'PARSE_SERVER_PAGES_ENABLE_ROUTER',
help: help:
'Is true if the pages router should be enabled; this is required for any of the pages options to take effect. Caution, this is an experimental feature that may not be appropriate for production.', 'Is true if the pages router should be enabled; this is required for any of the pages options to take effect.',
action: parsers.booleanParser, action: parsers.booleanParser,
default: false, default: false,
}, },

View File

@@ -75,7 +75,7 @@
* @property {String} mountPath Mount path for the server, defaults to /parse * @property {String} mountPath Mount path for the server, defaults to /parse
* @property {Boolean} mountPlayground Mounts the GraphQL Playground - never use this option in production * @property {Boolean} mountPlayground Mounts the GraphQL Playground - never use this option in production
* @property {Number} objectIdSize Sets the number of characters in generated object id's, default 10 * @property {Number} objectIdSize Sets the number of characters in generated object id's, default 10
* @property {PagesOptions} pages The options for pages such as password reset and email verification. Caution, this is an experimental feature that may not be appropriate for production. * @property {PagesOptions} pages The options for pages such as password reset and email verification.
* @property {PasswordPolicyOptions} passwordPolicy The password policy for enforcing password related rules. * @property {PasswordPolicyOptions} passwordPolicy The password policy for enforcing password related rules.
* @property {String} playgroundPath Mount path for the GraphQL Playground, defaults to /playground * @property {String} playgroundPath Mount path for the GraphQL Playground, defaults to /playground
* @property {Number} port The port to run the ParseServer, defaults to 1337. * @property {Number} port The port to run the ParseServer, defaults to 1337.
@@ -131,7 +131,7 @@
* @property {PagesRoute[]} customRoutes The custom routes. * @property {PagesRoute[]} customRoutes The custom routes.
* @property {PagesCustomUrlsOptions} customUrls The URLs to the custom pages. * @property {PagesCustomUrlsOptions} customUrls The URLs to the custom pages.
* @property {Boolean} enableLocalization Is true if pages should be localized; this has no effect on custom page redirects. * @property {Boolean} enableLocalization Is true if pages should be localized; this has no effect on custom page redirects.
* @property {Boolean} enableRouter Is true if the pages router should be enabled; this is required for any of the pages options to take effect. Caution, this is an experimental feature that may not be appropriate for production. * @property {Boolean} enableRouter Is true if the pages router should be enabled; this is required for any of the pages options to take effect.
* @property {Boolean} forceRedirect Is true if responses should always be redirects and never content, false if the response type should depend on the request type (GET request -> content response; POST request -> redirect response). * @property {Boolean} forceRedirect Is true if responses should always be redirects and never content, false if the response type should depend on the request type (GET request -> content response; POST request -> redirect response).
* @property {String} localizationFallbackLocale The fallback locale for localization if no matching translation is provided for the given locale. This is only relevant when providing translation resources via JSON file. * @property {String} localizationFallbackLocale The fallback locale for localization if no matching translation is provided for the given locale. This is only relevant when providing translation resources via JSON file.
* @property {String} localizationJsonPath The path to the JSON file for localization; the translations will be used to fill template placeholders according to the locale. * @property {String} localizationJsonPath The path to the JSON file for localization; the translations will be used to fill template placeholders according to the locale.

View File

@@ -217,7 +217,7 @@ export interface ParseServerOptions {
/* Public URL to your parse server with http:// or https://. /* Public URL to your parse server with http:// or https://.
:ENV: PARSE_PUBLIC_SERVER_URL */ :ENV: PARSE_PUBLIC_SERVER_URL */
publicServerURL: ?string; publicServerURL: ?string;
/* The options for pages such as password reset and email verification. Caution, this is an experimental feature that may not be appropriate for production. /* The options for pages such as password reset and email verification.
:DEFAULT: {} */ :DEFAULT: {} */
pages: ?PagesOptions; pages: ?PagesOptions;
/* custom pages for password validation and reset /* custom pages for password validation and reset
@@ -377,7 +377,7 @@ export interface SecurityOptions {
} }
export interface PagesOptions { export interface PagesOptions {
/* Is true if the pages router should be enabled; this is required for any of the pages options to take effect. Caution, this is an experimental feature that may not be appropriate for production. /* Is true if the pages router should be enabled; this is required for any of the pages options to take effect.
:DEFAULT: false */ :DEFAULT: false */
enableRouter: ?boolean; enableRouter: ?boolean;
/* Is true if pages should be localized; this has no effect on custom page redirects. /* Is true if pages should be localized; this has no effect on custom page redirects.

View File

@@ -5,11 +5,19 @@ import path from 'path';
import fs from 'fs'; import fs from 'fs';
import qs from 'querystring'; import qs from 'querystring';
import { Parse } from 'parse/node'; import { Parse } from 'parse/node';
import Deprecator from '../Deprecator/Deprecator';
const public_html = path.resolve(__dirname, '../../public_html'); const public_html = path.resolve(__dirname, '../../public_html');
const views = path.resolve(__dirname, '../../views'); const views = path.resolve(__dirname, '../../views');
export class PublicAPIRouter extends PromiseRouter { export class PublicAPIRouter extends PromiseRouter {
constructor() {
super();
Deprecator.logRuntimeDeprecation({
usage: 'PublicAPIRouter',
solution: 'pages.enableRouter'
});
}
verifyEmail(req) { verifyEmail(req) {
const { username, token: rawToken } = req.query; const { username, token: rawToken } = req.query;
const token = rawToken && typeof rawToken !== 'string' ? rawToken.toString() : rawToken; const token = rawToken && typeof rawToken !== 'string' ? rawToken.toString() : rawToken;