Skip to content
Closed
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: 4 additions & 2 deletions apps/docs/content/docs/dev/api/modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { buildModule } from "@vitnode/core/api/lib/module";
import { CONFIG_PLUGIN } from "@/config";

export const categoriesModule = buildModule({
pluginId: CONFIG_PLUGIN.id,
name: "categories",
routes: [] // We'll populate this soon!
});

export const categoriesModuleApi = categoriesModule.build(CONFIG_PLUGIN.pluginId);
```

#### Nested Modules
Expand All @@ -31,11 +32,12 @@ import { CONFIG_PLUGIN } from "@/config";
import { postsModule } from "./posts/posts.module"; // [!code ++]

export const categoriesModule = buildModule({
pluginId: CONFIG_PLUGIN.id,
name: "categories",
routes: [],
modules: [postsModule] // [!code ++]
});

export const categoriesModuleApi = categoriesModule.build(CONFIG_PLUGIN.pluginId);
```

This creates a structure: `/api/{plugin_id}/categories/posts/*`
Expand Down
12 changes: 2 additions & 10 deletions apps/docs/content/docs/dev/api/routes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ Now for the fun part - creating actual endpoints! Each route is a small but migh
import { z } from "@hono/zod-openapi";
import { buildRoute } from "@vitnode/core/api/lib/route";

import { CONFIG_PLUGIN } from "@/config";

export const getCategoriesRoute = buildRoute({
pluginId: CONFIG_PLUGIN.pluginId,
route: {
method: "get",
path: "/",
Expand Down Expand Up @@ -58,10 +55,11 @@ import { CONFIG_PLUGIN } from "@/config";
import { getCategoriesRoute } from "./routes/get.route"; // [!code ++]

export const categoriesModule = buildModule({
pluginId: CONFIG_PLUGIN.id,
name: "categories",
routes: [getCategoriesRoute] // [!code ++]
});

export const categoriesModuleApi = categoriesModule.build(CONFIG_PLUGIN.pluginId);
```

## Inputs
Expand All @@ -75,10 +73,7 @@ import { z } from "@hono/zod-openapi";
import { buildRoute } from "@vitnode/core/api/lib/route";
import { HTTPException } from "hono/http-exception";

import { CONFIG_PLUGIN } from "@/config";

export const getCategoryByIdRoute = buildRoute({
pluginId: CONFIG_PLUGIN.pluginId,
route: {
method: "get",
// [!code highlight]
Expand Down Expand Up @@ -136,10 +131,7 @@ Query parameters are your best friends for filtering, searching, and pagination.
import { z } from "@hono/zod-openapi";
import { buildRoute } from "@vitnode/core/api/lib/route";

import { CONFIG_PLUGIN } from "@/config";

export const searchCategoriesRoute = buildRoute({
pluginId: CONFIG_PLUGIN.pluginId,
route: {
method: "get",
path: "/search",
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/docs/dev/captcha/custom-adapter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ If you want to use captcha in your custom form or somewhere else, follow these s
import { buildRoute } from "@vitnode/core/api/lib/route";

export const exampleRoute = buildRoute({
pluginId: CONFIG_PLUGIN.pluginId,
route: {
method: "post",
description: "Create a new user",
Expand Down Expand Up @@ -96,14 +95,15 @@ export const FormSignUp = ({
import type { z } from "zod";

import { fetcher } from "@vitnode/core/lib/fetcher";
import { usersModuleApi } from "@vitnode/core/api/modules/users/users.module";

export const mutationApi = async ({
captchaToken, // [!code ++]
}: {
// [!code ++]
captchaToken;
}) => {
await fetcher(usersModule, {
await fetcher(usersModuleApi, {
path: "/test",
method: "post",
module: "blog",
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/content/docs/dev/captcha/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ Next, you need to set `captchaToken` in your mutation API call. This token is pr
import type { z } from "zod";

import { fetcher } from "@vitnode/core/lib/fetcher";
import { usersModuleApi } from "@vitnode/core/api/modules/users/users.module";

export const mutationApi = async ({
captchaToken, // [!code ++]
...input
}: // [!code ++]
z.infer<typeof zodSignUpSchema> & { captchaToken: string }) => {
const res = await fetcher(usersModule, {
const res = await fetcher(usersModuleApi, {
path: "/sign_up",
method: "post",
module: "users",
Expand Down
8 changes: 4 additions & 4 deletions apps/docs/content/docs/dev/fetcher.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ First, import the required dependencies:

```ts
import { fetcher } from '@vitnode/core/lib/fetcher';
import { usersModule } from '@vitnode/core/api/modules/users/users.module';
import { usersModuleApi } from '@vitnode/core/api/modules/users/users.module';
```

Make your first API call:

```ts
const response = await fetcher(usersModule, {
const response = await fetcher(usersModuleApi, {
path: '/session',
method: 'get',
module: 'users',
Expand Down Expand Up @@ -66,7 +66,7 @@ const response = await fetcher(categoriesAdminModule, {
You can leverage Next.js caching by passing cache options:

```ts
const response = await fetcher(usersModule, {
const response = await fetcher(usersModuleApi, {
path: '/session',
method: 'get',
module: 'users',
Expand All @@ -88,7 +88,7 @@ When working with authentication or sessions, you might need to handle cookies.
Here's how to enable cookie handling for a sign-in request:

```ts
const response = await fetcher(usersModule, {
const response = await fetcher(usersModuleApi, {
path: '/sign_in',
method: 'post',
module: 'users',
Expand Down
15 changes: 11 additions & 4 deletions apps/docs/src/app/[locale]/(docs)/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import { source } from "@/lib/source";

import { ViewOptions } from "./page.client";

export default async function Page(
props: PageProps<"/[locale]/docs/[[...slug]]">,
) {
interface DocsPageParams {
slug?: string[];
}

export default async function Page(props: { params: Promise<DocsPageParams> }) {
const params = await props.params;
if (!params.slug) {
await redirect("/docs/dev");

return null;
}
const page = source.getPage(params.slug);
if (!page) notFound();
Expand Down Expand Up @@ -58,9 +62,12 @@ export default async function Page(
// }

export async function generateMetadata(props: {
params: Promise<{ slug?: string[] }>;
params: Promise<DocsPageParams>;
}): Promise<Metadata> {
const params = await props.params;
if (!params.slug) {
notFound();
}
const page = source.getPage(params.slug);
if (!page) notFound();

Expand Down
37 changes: 17 additions & 20 deletions apps/docs/src/components/animated-beam/animated-beam-home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use client";

import type React from "react";

import {
Tooltip,
TooltipContent,
Expand All @@ -20,32 +18,31 @@ import {
Sparkle,
Users,
} from "lucide-react";
import { useRef } from "react";
import { type ComponentProps, type Ref, useRef } from "react";

import { LogoVitNode } from "../logo-vitnode";
import { AnimatedBeam } from "./animated-beam";

const Circle = ({
className,
tooltip,
...props
}: React.ComponentProps<typeof Link> & {
interface CircleProps extends ComponentProps<typeof Link> {
anchorRef?: Ref<HTMLAnchorElement>;
tooltip?: string;
}) => {
}

const Circle = ({ className, tooltip, anchorRef, ...props }: CircleProps) => {
const classNameLink = cn(
"bg-card hover:bg-accent hover:text-accent-foreground focus-visible:border-ring focus-visible:ring-ring/50 z-10 flex size-12 items-center justify-center rounded-md border p-3 transition-all focus-visible:ring-[3px]",
className,
);

if (!tooltip) {
return <Link className={classNameLink} {...props} />;
return <Link className={classNameLink} ref={anchorRef} {...props} />;
}

return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Link className={classNameLink} {...props} />
<Link className={classNameLink} ref={anchorRef} {...props} />
</TooltipTrigger>

<TooltipContent>{tooltip}</TooltipContent>
Expand Down Expand Up @@ -75,40 +72,40 @@ export function AnimatedBeamHome() {
>
<div className="flex size-full max-w-lg flex-col items-stretch justify-between gap-10">
<div className="flex flex-row items-center justify-between">
<Circle href="/" ref={div1Ref} tooltip="Users">
<Circle anchorRef={div1Ref} href="/" tooltip="Users">
<Users />
</Circle>
<Circle
anchorRef={div8Ref}
href="/docs/dev/email/overview"
ref={div8Ref}
tooltip="Emails"
>
<AtSign />
</Circle>
<Circle href="/" ref={div5Ref} tooltip="Plugins">
<Circle anchorRef={div5Ref} href="/" tooltip="Plugins">
<Plug />
</Circle>
</div>
<div className="flex flex-row items-center justify-between">
<Circle href="/" ref={div2Ref} tooltip="Languages">
<Circle anchorRef={div2Ref} href="/" tooltip="Languages">
<Languages />
</Circle>

<Circle className="size-16" href="/docs/dev" ref={div4Ref}>
<Circle anchorRef={div4Ref} className="size-16" href="/docs/dev">
<LogoVitNode small />
</Circle>
<Circle href="/" ref={div6Ref} tooltip="Themes">
<Circle anchorRef={div6Ref} href="/" tooltip="Themes">
<Paintbrush />
</Circle>
</div>
<div className="flex flex-row items-center justify-between">
<Circle href="/" ref={div3Ref} tooltip="Authorization">
<Circle anchorRef={div3Ref} href="/" tooltip="Authorization">
<ShieldCheck />
</Circle>
<Circle href="/" ref={div9Ref} tooltip="AI">
<Circle anchorRef={div9Ref} href="/" tooltip="AI">
<Sparkle />
</Circle>
<Circle href="/" ref={div7Ref} tooltip="Database">
<Circle anchorRef={div7Ref} href="/" tooltip="Database">
<Database />
</Circle>
</div>
Expand Down
Loading
Loading