mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 07:35:16 +00:00
Move ~scalar/proxy route to site route group (#4083)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@gitbook/react-openapi": patch
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Move ~scalar/proxy route to site route group
|
||||||
@@ -32,8 +32,11 @@ export function getOpenAPIContext(args: {
|
|||||||
const customizationLocale = context ? getSpaceLocale(context) : DEFAULT_LOCALE;
|
const customizationLocale = context ? getSpaceLocale(context) : DEFAULT_LOCALE;
|
||||||
const locale = checkIsValidLocale(customizationLocale) ? customizationLocale : DEFAULT_LOCALE;
|
const locale = checkIsValidLocale(customizationLocale) ? customizationLocale : DEFAULT_LOCALE;
|
||||||
|
|
||||||
|
const proxyUrl = context ? context.linker.toPathInSite('~scalar/proxy') : undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
specUrl,
|
specUrl,
|
||||||
|
proxyUrl,
|
||||||
icons: {
|
icons: {
|
||||||
chevronDown: <Icon icon="chevron-down" />,
|
chevronDown: <Icon icon="chevron-down" />,
|
||||||
chevronRight: <Icon icon="chevron-right" />,
|
chevronRight: <Icon icon="chevron-right" />,
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import { getPreviewRequestIdentifier } from './lib/preview';
|
|||||||
import { serveProxyAnalyticsEvent } from './lib/tracking';
|
import { serveProxyAnalyticsEvent } from './lib/tracking';
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: [
|
matcher: [
|
||||||
'/((?!_next/static|_next/image|~gitbook/static|~gitbook/revalidate|~gitbook/monitoring|~scalar/proxy).*)',
|
'/((?!_next/static|_next/image|~gitbook/static|~gitbook/revalidate|~gitbook/monitoring).*)',
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -663,6 +663,7 @@ function encodePathInSiteContent(
|
|||||||
return { pathname, routeType: 'static' };
|
return { pathname, routeType: 'static' };
|
||||||
case '~gitbook/pdf':
|
case '~gitbook/pdf':
|
||||||
case '~gitbook/search':
|
case '~gitbook/search':
|
||||||
|
case '~scalar/proxy':
|
||||||
// PDF and search routes are always dynamic as they depend on the request.
|
// PDF and search routes are always dynamic as they depend on the request.
|
||||||
return { pathname, routeType: 'dynamic' };
|
return { pathname, routeType: 'dynamic' };
|
||||||
default: {
|
default: {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ export function ScalarApiButton(props: {
|
|||||||
<ScalarModal
|
<ScalarModal
|
||||||
controllerRef={controllerRef}
|
controllerRef={controllerRef}
|
||||||
withProxy={withProxy}
|
withProxy={withProxy}
|
||||||
|
proxyUrl={context.proxyUrl}
|
||||||
method={method}
|
method={method}
|
||||||
path={path}
|
path={path}
|
||||||
securities={securities}
|
securities={securities}
|
||||||
@@ -73,9 +74,11 @@ function ScalarModal(props: {
|
|||||||
servers: OpenAPIOperationData['servers'];
|
servers: OpenAPIOperationData['servers'];
|
||||||
specUrl: string;
|
specUrl: string;
|
||||||
withProxy: boolean;
|
withProxy: boolean;
|
||||||
|
proxyUrl?: string;
|
||||||
controllerRef: React.Ref<ScalarModalControllerRef>;
|
controllerRef: React.Ref<ScalarModalControllerRef>;
|
||||||
}) {
|
}) {
|
||||||
const { method, path, securities, servers, specUrl, withProxy, controllerRef } = props;
|
const { method, path, securities, servers, specUrl, withProxy, proxyUrl, controllerRef } =
|
||||||
|
props;
|
||||||
|
|
||||||
const getPrefillInputContextData = useOpenAPIPrefillContext();
|
const getPrefillInputContextData = useOpenAPIPrefillContext();
|
||||||
const prefillInputContext = getPrefillInputContextData();
|
const prefillInputContext = getPrefillInputContextData();
|
||||||
@@ -90,7 +93,7 @@ function ScalarModal(props: {
|
|||||||
configuration={{
|
configuration={{
|
||||||
url: specUrl,
|
url: specUrl,
|
||||||
...prefillConfig,
|
...prefillConfig,
|
||||||
proxyUrl: withProxy ? '/~scalar/proxy' : undefined,
|
proxyUrl: withProxy ? proxyUrl : undefined,
|
||||||
}}
|
}}
|
||||||
initialRequest={{ method: toScalarHttpMethod(method), path }}
|
initialRequest={{ method: toScalarHttpMethod(method), path }}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ export interface OpenAPIClientContext {
|
|||||||
*/
|
*/
|
||||||
id?: string;
|
id?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL for the Scalar proxy endpoint.
|
||||||
|
*/
|
||||||
|
proxyUrl?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the context as a client context.
|
* Mark the context as a client context.
|
||||||
*/
|
*/
|
||||||
@@ -97,6 +102,7 @@ export function getOpenAPIClientContext(context: OpenAPIUniversalContext): OpenA
|
|||||||
defaultInteractiveOpened: context.defaultInteractiveOpened,
|
defaultInteractiveOpened: context.defaultInteractiveOpened,
|
||||||
blockKey: context.blockKey,
|
blockKey: context.blockKey,
|
||||||
id: context.id,
|
id: context.id,
|
||||||
|
proxyUrl: context.proxyUrl,
|
||||||
$$isClientContext$$: true,
|
$$isClientContext$$: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user