Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions demo/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const config = {
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
proxy: {
"/proxy": {
target: "http://localhost:8091",
pathRewrite: { "^/proxy": "" },
},
},
}),
],
],
Expand Down
28 changes: 28 additions & 0 deletions packages/docusaurus-plugin-proxy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "docusaurus-plugin-proxy",
"description": "A dev server proxy for Docusaurus.",
"version": "0.2.3",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"types": "src/plugin-proxy.d.ts",
"main": "dist/index.js",
"scripts": {
"build": "scripts/build.ts",
"watch": "scripts/build.ts --watch"
},
"devDependencies": {
"@types/concurrently": "^6.3.0",
"@types/webpack-dev-server": "^4.5.0",
"concurrently": "^5.2.0",
"cpx": "^1.5.0"
},
"dependencies": {
"@docusaurus/core": "^2.0.0-beta.13",
"@docusaurus/types": "^2.0.0-beta.13"
},
"engines": {
"node": ">=14"
}
}
36 changes: 36 additions & 0 deletions packages/docusaurus-plugin-proxy/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env ts-node
/* ============================================================================
* Copyright (c) Cloud Annotations
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

import concurrently, { CommandObj } from "concurrently";

const watch = process.argv.includes("--watch");

const watchFlag = watch ? "--watch" : "";

const commands: CommandObj[] = [
{
command: `tsc --preserveWatchOutput ${watchFlag}`,
name: "tsc",
prefixColor: "yellow",
},
{
// Copy all files BUT *.ts and *.tsx (which will be turned into JS by TS).
// Notice that we include *.d.ts, they're perfectly valid to copy.
command: `cpx 'src/**/{*.d.ts,!(*.ts|*.tsx)}' dist ${watchFlag}`,
name: "cpx",
prefixColor: "yellow",
},
];

concurrently(commands, {
killOthers: ["failure"],
prefix: "[{time} {name}]",
timestampFormat: "mm:ss.S",
}).catch(() => {
process.exit(1);
});
29 changes: 29 additions & 0 deletions packages/docusaurus-plugin-proxy/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* ============================================================================
* Copyright (c) Cloud Annotations
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

import { LoadContext, Plugin } from "@docusaurus/types";

import { PluginOptions } from "./types";

export default function pluginOpenAPI(
_context: LoadContext,
options: PluginOptions
): Plugin {
return {
name: "docusaurus-plugin-proxy",

configureWebpack() {
const { proxy } = options;

return {
devServer: {
proxy: proxy,
},
} as any;
},
};
}
12 changes: 12 additions & 0 deletions packages/docusaurus-plugin-proxy/src/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* ============================================================================
* Copyright (c) Cloud Annotations
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

import type { PluginOptions } from "./types";

export const DEFAULT_OPTIONS: Omit<PluginOptions, "id"> = {
proxy: undefined,
};
10 changes: 10 additions & 0 deletions packages/docusaurus-plugin-proxy/src/plugin-proxy.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* ============================================================================
* Copyright (c) Cloud Annotations
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

declare module "docusaurus-plugin-proxy" {
export type Options = Partial<import("./types").PluginOptions>;
}
12 changes: 12 additions & 0 deletions packages/docusaurus-plugin-proxy/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* ============================================================================
* Copyright (c) Cloud Annotations
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

import type { Configuration } from "webpack-dev-server";

export interface PluginOptions {
proxy: Configuration["proxy"];
}
7 changes: 7 additions & 0 deletions packages/docusaurus-plugin-proxy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src"]
}
1 change: 1 addition & 0 deletions packages/docusaurus-preset-openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@docusaurus/theme-classic": "2.0.0-beta.13",
"@docusaurus/theme-search-algolia": "2.0.0-beta.13",
"docusaurus-plugin-openapi": "^0.2.3",
"docusaurus-plugin-proxy": "^0.2.3",
"docusaurus-theme-openapi": "^0.2.3"
},
"peerDependencies": {
Expand Down
6 changes: 5 additions & 1 deletion packages/docusaurus-preset-openapi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function preset(
context: LoadContext,
options: Options = {}
): Preset {
const { api, ...rest } = options;
const { proxy, api, ...rest } = options;

const { themes = [], plugins = [] } = presetClassic(context, rest);

Expand All @@ -33,5 +33,9 @@ export default function preset(
plugins.push(makePluginConfig("docusaurus-plugin-openapi", api));
}

if (proxy !== false) {
plugins.push(makePluginConfig("docusaurus-plugin-proxy", proxy));
}

return { themes, plugins };
}
1 change: 1 addition & 0 deletions packages/docusaurus-preset-openapi/src/preset-openapi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {

export type Options = {
api?: false | import("docusaurus-plugin-openapi").Options;
proxy?: false | import("docusaurus-plugin-proxy").Options;
} & ClassicOptions;

export type ThemeConfig = import("docusaurus-theme-openapi").ThemeConfig &
Expand Down
Loading