mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-14 00:26:06 +00:00
docs: vendor the documentation site into the monorepo
Fold the standalone 3x-ui-docs project (Next.js 16 + Fumadocs, deployed to docs.sanaei.dev) into docs/ so the panel and its documentation share a single source of truth, the way sing-box keeps its docs in-tree. The old repo becomes redundant and can be retired. - Import the full site under docs/ (app, components, content, lib, public, scripts, config). The self-contained pnpm project sits alongside the existing engineering notes with no filename collisions. - Re-point "Edit on GitHub" links from MHSanaei/3x-ui-docs to this repo's docs/content/docs path (docs/lib/shared.ts, docs/app/.../page.tsx). - Add docs-ci.yml and docs-deploy.yml under .github/workflows/, scoped to docs/** and run with working-directory: docs, since GitHub only runs workflows from the repo-root .github/. deploy-static.yml's GitHub Pages publish (CNAME docs.sanaei.dev) carries over unchanged. Follow-up (outside this commit): attach the docs.sanaei.dev custom domain to this repository's Pages (or set the Vercel project's root directory to docs), confirm the site is live from the monorepo, then delete MHSanaei/3x-ui-docs.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { normalizeBase, joinUrl, buildCurl, buildFetchSnippet } from './api-client';
|
||||
|
||||
describe('normalizeBase', () => {
|
||||
it('strips a trailing slash', () => {
|
||||
expect(normalizeBase('https://panel.example.com:2053/')).toBe('https://panel.example.com:2053');
|
||||
});
|
||||
|
||||
it('leaves a clean base unchanged', () => {
|
||||
expect(normalizeBase('https://panel.example.com:2053')).toBe('https://panel.example.com:2053');
|
||||
});
|
||||
});
|
||||
|
||||
describe('joinUrl', () => {
|
||||
it('joins with exactly one slash regardless of input slashes', () => {
|
||||
expect(joinUrl('https://x.com/', 'panel/api/inbounds/list')).toBe(
|
||||
'https://x.com/panel/api/inbounds/list',
|
||||
);
|
||||
expect(joinUrl('https://x.com', '/panel/api/inbounds/list')).toBe(
|
||||
'https://x.com/panel/api/inbounds/list',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const base = {
|
||||
baseUrl: 'https://panel.example.com:2053',
|
||||
token: 'TKN',
|
||||
path: '/panel/api/inbounds/list',
|
||||
};
|
||||
|
||||
describe('buildCurl', () => {
|
||||
it('GET emits the Bearer header, a single-quoted URL, and no body flag', () => {
|
||||
const cmd = buildCurl({ ...base, method: 'GET' });
|
||||
expect(cmd).toContain("-X GET");
|
||||
expect(cmd).toContain("-H 'Authorization: Bearer TKN'");
|
||||
expect(cmd).toContain("'https://panel.example.com:2053/panel/api/inbounds/list'");
|
||||
expect(cmd).not.toContain('--data');
|
||||
expect(cmd).not.toContain('-d ');
|
||||
});
|
||||
|
||||
it('POST with a body emits --data and a JSON content type', () => {
|
||||
const cmd = buildCurl({ ...base, method: 'POST', path: '/panel/api/inbounds/add', body: '{"up":0}' });
|
||||
expect(cmd).toContain('-X POST');
|
||||
expect(cmd).toContain("--data '{\"up\":0}'");
|
||||
expect(cmd).toContain("Content-Type: application/json");
|
||||
});
|
||||
|
||||
it('POST without a body omits --data', () => {
|
||||
const cmd = buildCurl({ ...base, method: 'POST', path: '/panel/api/inbounds/resetAllTraffics' });
|
||||
expect(cmd).not.toContain('--data');
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildFetchSnippet', () => {
|
||||
it('GET sets method + Authorization and no body', () => {
|
||||
const snip = buildFetchSnippet({ ...base, method: 'GET' });
|
||||
expect(snip).toContain("method: 'GET'");
|
||||
expect(snip).toContain("'Authorization': 'Bearer TKN'");
|
||||
expect(snip).not.toContain('body:');
|
||||
});
|
||||
|
||||
it('POST with a body includes a JSON.stringify body', () => {
|
||||
const snip = buildFetchSnippet({ ...base, method: 'POST', path: '/panel/api/inbounds/add', body: '{"up":0}' });
|
||||
expect(snip).toContain("method: 'POST'");
|
||||
expect(snip).toContain('body: JSON.stringify(');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user