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
7 changes: 1 addition & 6 deletions app/[locale]/(home)/_pages/page.en.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function HomePage() {
<Cards>
<SmallCard
icon={<Chainhook />}
badge="beta"
href="/tools/chainhook"
title="Chainhook"
description="Create custom event streams and triggers for real-time blockchain data processing."
Expand Down Expand Up @@ -135,12 +136,6 @@ export default function HomePage() {
title="Guides"
description="Step-by-step walkthroughs for building on Bitcoin layers."
/>
<SmallCard
icon={<Braces />}
href="/resources/snippets"
title="Snippets"
description="Reusable code examples for common Stacks and Bitcoin tasks."
/>
<SmallCard
icon={<Database />}
href="/resources/archive"
Expand Down
1 change: 1 addition & 0 deletions app/[locale]/(home)/_pages/page.es.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions app/[locale]/(home)/resources/_pages/page.en.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ export default function ResourcesPage() {
title="Guides"
description="Guides for building on Stacks and Bitcoin."
/>
{/* <IndexCard
icon={<Braces />}
href="/resources/templates"
title="Project templates"
description="Project templates for building on Stacks and Bitcoin."
/> */}
<IndexCard
icon={<Code />}
href="/resources/snippets"
title="Snippets"
description="Code snippets for building on Stacks and Bitcoin."
/>
<IndexCard
icon={<Database />}
href="/resources/archive"
Expand Down
3 changes: 3 additions & 0 deletions app/[locale]/(home)/tools/_pages/page.en.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ export default function ToolsPage() {
href="/tools/chainhook"
title="Chainhook"
icon={<Chainhook />}
badge="beta"
tag="Stacks"
description="Create custom event streams and triggers for real-time blockchain data processing."
/>
<IndexCard
href="/tools/contract-monitoring"
title="Contract Monitoring"
icon={<Brackets />}
tag="Stacks"
description="Monitor and track smart contract activity and performance metrics."
/>
<IndexCard
Expand Down
3 changes: 3 additions & 0 deletions app/[locale]/(home)/tools/_pages/page.es.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 27 additions & 16 deletions app/[locale]/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { API } from '@/components/reference/api-page';
import { Badge } from '@/components/ui/badge';
import * as customIcons from '@/components/ui/icon';
import { TagFilterSystem } from '@/components/ui/tag-filter-system';
import { getAPIConfig } from '@/lib/api-config';
import { i18n } from '@/lib/i18n';
import { getAllFilterablePages, source } from '@/lib/source';
import type { HeadingProps } from '@/types';
Expand Down Expand Up @@ -138,14 +139,19 @@ export default async function Page(props: {
components={getMDXComponents({
// Custom overrides that need special handling
API: (props) => <API {...props} />,
APIPage: (props) => (
<APIPage
baseUrl="https://api.hiro.so"
enablePlayground={true}
clarityConversion={true}
{...props}
/>
),
APIPage: (props) => {
const config = props.document
? getAPIConfig(String(props.document))
: undefined;

const mergedProps = {
...(config ?? {}),
...props,
playgroundOptions: props.playgroundOptions ?? config?.playgroundOptions,
};

return <APIPage {...mergedProps} />;
},
h1: ({ children, ...props }: HeadingProps) => {
const H1 = defaultMdxComponents.h1 as React.ComponentType<HeadingProps>;
const id = typeof children === 'string' ? children : undefined;
Expand Down Expand Up @@ -238,14 +244,19 @@ export default async function Page(props: {
components={getMDXComponents({
// Custom overrides that need special handling
API: (props) => <API {...props} />,
APIPage: (props) => (
<APIPage
baseUrl="https://api.hiro.so"
enablePlayground={true}
clarityConversion={true}
{...props}
/>
),
APIPage: (props) => {
const config = props.document
? getAPIConfig(String(props.document))
: undefined;

const mergedProps = {
...(config ?? {}),
...props,
playgroundOptions: props.playgroundOptions ?? config?.playgroundOptions,
};

return <APIPage {...mergedProps} />;
},
h1: ({ children, ...props }: HeadingProps) => {
const H1 = defaultMdxComponents.h1 as React.ComponentType<HeadingProps>;
const id = typeof children === 'string' ? children : undefined;
Expand Down
86 changes: 86 additions & 0 deletions app/api/proxy/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { NextResponse } from 'next/server';

const ALLOWED_METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);
const ALLOWED_HOSTNAMES = new Set(['api.hiro.so', 'api.mainnet.hiro.so', 'api.testnet.hiro.so']);
const BLOCKED_REQUEST_HEADERS = new Set(['host', 'cookie', 'connection', 'content-length']);
const STRIPPED_RESPONSE_HEADERS = new Set(['set-cookie', 'server', 'via', 'www-authenticate']);

export const dynamic = 'force-dynamic';

export async function POST(request: Request) {
try {
const { url, method = 'GET', headers = {}, body } = await request.json();

if (!url || typeof url !== 'string') {
return NextResponse.json({ error: 'A target URL is required.' }, { status: 400 });
}

let parsedUrl: URL;
try {
parsedUrl = new URL(url);
} catch {
return NextResponse.json({ error: 'URL must be absolute.' }, { status: 400 });
}

if (parsedUrl.protocol !== 'https:' || !ALLOWED_HOSTNAMES.has(parsedUrl.hostname)) {
return NextResponse.json(
{ error: 'This proxy only allows Hiro API hosts over HTTPS.' },
{ status: 403 },
);
}

const upperMethod = String(method).toUpperCase();
if (!ALLOWED_METHODS.has(upperMethod)) {
return NextResponse.json(
{ error: `Method ${upperMethod} is not supported by the proxy.` },
{ status: 405 },
);
}

const upstreamHeaders = new Headers();
if (headers && typeof headers === 'object') {
for (const [key, value] of Object.entries(headers)) {
if (typeof value === 'string' && !BLOCKED_REQUEST_HEADERS.has(key.toLowerCase())) {
upstreamHeaders.set(key, value);
}
}
}

const requestInit: RequestInit = {
method: upperMethod,
headers: upstreamHeaders,
};

if (body !== undefined && body !== null && upperMethod !== 'GET' && upperMethod !== 'HEAD') {
requestInit.body = typeof body === 'string' ? body : JSON.stringify(body);
}

const upstreamResponse = await fetch(parsedUrl, requestInit);
const contentType = upstreamResponse.headers.get('content-type') ?? '';
let data: unknown;

if (contentType.includes('application/json')) {
data = await upstreamResponse.json();
} else {
data = await upstreamResponse.text();
}

const sanitizedHeaders = Object.fromEntries(
Array.from(upstreamResponse.headers.entries()).filter(
([key]) => !STRIPPED_RESPONSE_HEADERS.has(key.toLowerCase()),
),
);

return NextResponse.json({
status: upstreamResponse.status,
statusText: upstreamResponse.statusText,
headers: sanitizedHeaders,
data,
});
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : 'Proxy request failed.' },
{ status: 500 },
);
}
}
23 changes: 7 additions & 16 deletions app/layout.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const baseOptions: BaseLayoutProps = {
text: 'Chainhook',
description: 'Monitor and analyze Clarity smart contract activity.',
url: '/tools/chainhook',
isBeta: true,
},
{
text: 'Contract Monitoring',
Expand All @@ -35,7 +36,6 @@ export const baseOptions: BaseLayoutProps = {
text: 'Bitcoin Indexer',
description: 'Indexer for Bitcoin blockchain data.',
url: '/tools/bitcoin-indexer',
isNew: true,
},
],
},
Expand Down Expand Up @@ -69,6 +69,12 @@ export const baseOptions: BaseLayoutProps = {
description: 'API for retrieving NFT and fungible token metadata.',
url: '/apis/token-metadata-api',
},
{
text: 'Chainhook API',
description: 'RESTful API for accessing Chainhook',
url: '/apis/chainhook-api',
isNew: true,
},
{
text: 'Platform API',
description: 'API for accessing Hiro Platform data and functionality.',
Expand Down Expand Up @@ -100,26 +106,11 @@ export const baseOptions: BaseLayoutProps = {
description: 'Guides for building on Stacks.',
url: '/resources/guides',
},
// {
// text: "Project templates",
// description: "Project templates for building on Stacks.",
// url: "/resources/templates",
// },
{
text: 'Snippets',
description: 'Code snippets for building on Stacks and Bitcoin.',
url: '/resources/snippets',
},
{
text: 'Hiro Archive',
description: 'Archive of blockchain data.',
url: '/resources/archive',
},
// {
// text: "Faucets",
// description: "Faucets for getting testnet tokens.",
// url: "/resources/faucets",
// },
],
},
],
Expand Down
21 changes: 12 additions & 9 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RootProvider } from 'fumadocs-ui/provider';
import type { ReactNode } from 'react';
import { aeonik, aeonikFono, aeonikMono, inter } from '@/fonts';
import { KeyboardShortcutsProvider } from '@/hooks/use-keyboard-shortcuts';
import { ApiCredentialsProvider } from '@/providers/api-credentials-provider';
import { QueryProvider } from '@/providers/query-provider';

export default function RootLayout({ children }: { children: ReactNode }) {
Expand All @@ -14,15 +15,17 @@ export default function RootLayout({ children }: { children: ReactNode }) {
>
<body className="flex flex-col min-h-screen">
<QueryProvider>
<KeyboardShortcutsProvider>
<RootProvider
search={{
enabled: true,
}}
>
{children}
</RootProvider>
</KeyboardShortcutsProvider>
<ApiCredentialsProvider>
<KeyboardShortcutsProvider>
<RootProvider
search={{
enabled: true,
}}
>
{children}
</RootProvider>
</KeyboardShortcutsProvider>
</ApiCredentialsProvider>
</QueryProvider>
</body>
</html>
Expand Down
Loading