Add custom routes to pages router (#7231)

* added custom routes

* fixed docs typos

* added page.customRoutes config validation

* added 404 response if missing custom route response

* added docs

* minor README formatting

* added CHANGELOG entry

* fixed bug in definitions builder that did not recognize array of custom type

* added missing route handler definition

* fixed custom routes definition
This commit is contained in:
Manuel
2021-03-07 13:51:35 +01:00
committed by GitHub
parent cac6951be0
commit de50b7b23d
10 changed files with 327 additions and 17 deletions

View File

@@ -425,6 +425,12 @@ module.exports.ParseServerOptions = {
},
};
module.exports.PagesOptions = {
customRoutes: {
env: 'PARSE_SERVER_PAGES_CUSTOM_ROUTES',
help: 'The custom routes.',
action: parsers.arrayParser,
default: [],
},
customUrls: {
env: 'PARSE_SERVER_PAGES_CUSTOM_URLS',
help: 'The URLs to the custom pages.',
@@ -481,6 +487,23 @@ module.exports.PagesOptions = {
default: {},
},
};
module.exports.PagesRoute = {
handler: {
env: 'PARSE_SERVER_PAGES_ROUTE_HANDLER',
help: 'The route handler that is an async function.',
required: true,
},
method: {
env: 'PARSE_SERVER_PAGES_ROUTE_METHOD',
help: "The route method, e.g. 'GET' or 'POST'.",
required: true,
},
path: {
env: 'PARSE_SERVER_PAGES_ROUTE_PATH',
help: 'The route path.',
required: true,
},
};
module.exports.PagesCustomUrlsOptions = {
emailVerificationLinkExpired: {
env: 'PARSE_SERVER_PAGES_CUSTOM_URL_EMAIL_VERIFICATION_LINK_EXPIRED',

View File

@@ -82,6 +82,7 @@
/**
* @interface PagesOptions
* @property {PagesRoute[]} customRoutes The custom routes.
* @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} 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.
@@ -93,6 +94,13 @@
* @property {Object} placeholders The placeholder keys and values which will be filled in pages; this can be a simple object or a callback function.
*/
/**
* @interface PagesRoute
* @property {Function} handler The route handler that is an async function.
* @property {String} method The route method, e.g. 'GET' or 'POST'.
* @property {String} path The route path.
*/
/**
* @interface PagesCustomUrlsOptions
* @property {String} emailVerificationLinkExpired The URL to the custom page for email verification -> link expired.

View File

@@ -256,6 +256,18 @@ export interface PagesOptions {
/* The URLs to the custom pages.
:DEFAULT: {} */
customUrls: ?PagesCustomUrlsOptions;
/* The custom routes.
:DEFAULT: [] */
customRoutes: ?(PagesRoute[]);
}
export interface PagesRoute {
/* The route path. */
path: string;
/* The route method, e.g. 'GET' or 'POST'. */
method: string;
/* The route handler that is an async function. */
handler: () => void;
}
export interface PagesCustomUrlsOptions {