8000 Invisible proxy by Sytten · Pull Request #157 · caido/documentation · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Invisible proxy #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 19, 2025
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
76 changes: 76 additions & 0 deletions .vitepress/components/Mermaid.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from "vue";
import type { MermaidConfig } from "mermaid";
import mermaid from "mermaid";

const props = defineProps({
graph: {
type: String,
required: true,
},
id: {
type: String,
required: true,
},
});

const svg = ref("");
const code = ref(decodeURIComponent(props.graph));

let mut: MutationObserver | null = null;

onMounted(async () => {
mut = new MutationObserver(() => {
renderChart();
});
mut.observe(document.documentElement, { attributes: true });

await renderChart();

//refresh images on first render
const hasImages = (/<img([\w\W]+?)>/.exec(code.value)?.length ?? 0) > 0;
if (hasImages)
setTimeout(() => {
let imgElements = document.getElementsByTagName("img");
let imgs = Array.from(imgElements);
if (imgs.length) {
Promise.all(
imgs
.filter((img) => !img.complete)
.map(
(img) =>
new Promise((resolve) => {
img. = resolve;
}),
),
).then(() => {
renderChart();
});
}
}, 100);
});

onUnmounted(() => mut?.disconnect());

const renderChart = async () => {
const mermaidConfig: MermaidConfig = {
securityLevel: "loose",
startOnLoad: false,
theme: "dark",
};
mermaid.initialize(mermaidConfig);
const render = await mermaid.render(props.id, code.value);
// This is a hack to force v-html to re-render, otherwise the diagram disappears
// when **switching themes** or **reloading the page**.
// The cause is that the diagram is deleted during rendering (out of Vue's knowledge).
// Because svgCode does NOT change, v-html does not re-render.
// This is not required for all diagrams, but it is required for c4c, mindmap and zenuml.
const salt = Math.random().toString(36).substring(7);
svg.value = `${render.svg} <span style="display: none">${salt}</span>`;
};
</script>

<template>
<!-- eslint-disable-next-line vue/no-v-html -->
<div v-html="svg" />
</template>
7 changes: 7 additions & 0 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
referenceSidebar,
tutorialsSidebar,
} from "./sidebars";
import MermaidExample from "./mermaid";

// https://vitepress.dev/reference/site-config
export default defineConfig({
Expand Down Expand Up @@ -34,6 +35,12 @@ export default defineConfig({
],
ignoreDeadLinks: "localhostLinks",

markdown: {
config: (md) => {
MermaidExample(md);
},
},

themeConfig: {
logo: {
src: "/logo.png",
Expand Down
32 changes: 32 additions & 0 deletions .vitepress/mermaid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { MarkdownRenderer } from "vitepress";

const MermaidExample = (md: MarkdownRenderer) => {
const defaultRenderer = md.renderer.rules.fence;

if (!defaultRenderer) {
throw new Error("defaultRenderer is undefined");
}

md.renderer.rules.fence = (tokens, index, options, env, slf) => {
const token = tokens[index]!;
const language = token.info.trim();
if (language.startsWith("mermaid")) {
const key = index;
return `
<Suspense>
<template #default>
<Mermaid id="mermaid-${key}" graph="${encodeURIComponent(token.content)}" />
</template>
<!-- loading state via #fallback slot -->
<template #fallback>
Loading...
</template>
</Suspense>
`;
}

return defaultRenderer(tokens, index, options, env, slf);
};
};

export default MermaidExample;
13 changes: 13 additions & 0 deletions .vitepress/sidebars/concepts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ export const conceptsSidebar: DefaultTheme.SidebarItem[] = [
},
],
},
{
text: "Proxying",
items: [
{
text: "Traffic splitting",
link: "/concepts/proxying/traffic_splitting",
},
{
text: "Invisible Proxying",
link: "/concepts/proxying/invisible",
},
],
},
{
text: "Workflows",
items: [
Expand Down
4 changes: 4 additions & 0 deletions .vitepress/sidebars/guides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export const guidesSidebar: DefaultTheme.SidebarItem[] = [
text: "Upstream to Another Proxy",
link: "/guides/upstream",
},
{
text: "Enabling invisible proxying",
link: "/guides/invisible_proxying",
},
],
},
{
Expand Down
2 changes: 2 additions & 0 deletions .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import DefaultTheme from "vitepress/theme";
import "./custom.css";

import ProContainer from "../components/Pro.vue";
import Mermaid from "../components/Mermaid.vue";
import type { Theme } from "vitepress";

export default {
extends: DefaultTheme,
enhanceApp({ app }) {
app.component("ProContainer", ProContainer);
app.component("Mermaid", Mermaid);
},
} satisfies Theme;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-vue": "9.27.0",
"markdownlint-cli2": "0.14.0",
"mermaid": "11.4.1",
"typescript": "5.6.2",
"typescript-eslint": "8.5.0",
"vitepress": "1.2.2",
"vue": "3.4.27",
"vue-eslint-parser": "9.4.3"
}
}
Loading
0