diff --git a/link-shortner/.gitignore b/link-shortner/.gitignore new file mode 100644 index 0000000..2971a0b --- /dev/null +++ b/link-shortner/.gitignore @@ -0,0 +1,42 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# database +/prisma/db.sqlite +/prisma/db.sqlite-journal + +# next.js +/.next/ +/out/ +next-env.d.ts + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# local env files +# do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables +.env +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo diff --git a/link-shortner/README.md b/link-shortner/README.md new file mode 100644 index 0000000..fba19ed --- /dev/null +++ b/link-shortner/README.md @@ -0,0 +1,28 @@ +# Create T3 App + +This is a [T3 Stack](https://create.t3.gg/) project bootstrapped with `create-t3-app`. + +## What's next? How do I make an app with this? + +We try to keep this project as simple as possible, so you can start with just the scaffolding we set up for you, and add additional things later when they become necessary. + +If you are not familiar with the different technologies used in this project, please refer to the respective docs. If you still are in the wind, please join our [Discord](https://t3.gg/discord) and ask for help. + +- [Next.js](https://nextjs.org) +- [NextAuth.js](https://next-auth.js.org) +- [Prisma](https://prisma.io) +- [Tailwind CSS](https://tailwindcss.com) +- [tRPC](https://trpc.io) + +## Learn More + +To learn more about the [T3 Stack](https://create.t3.gg/), take a look at the following resources: + +- [Documentation](https://create.t3.gg/) +- [Learn the T3 Stack](https://create.t3.gg/en/faq#what-learning-resources-are-currently-available) — Check out these awesome tutorials + +You can check out the [create-t3-app GitHub repository](https://github.com/t3-oss/create-t3-app) — your feedback and contributions are welcome! + +## How do I deploy this? + +Follow our deployment guides for [Vercel](https://create.t3.gg/en/deployment/vercel), [Netlify](https://create.t3.gg/en/deployment/netlify) and [Docker](https://create.t3.gg/en/deployment/docker) for more information. diff --git a/link-shortner/bun.lockb b/link-shortner/bun.lockb new file mode 100755 index 0000000..a415aaf Binary files /dev/null and b/link-shortner/bun.lockb differ diff --git a/link-shortner/components.json b/link-shortner/components.json new file mode 100644 index 0000000..3dc9445 --- /dev/null +++ b/link-shortner/components.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://ui.shadcn.com/schema.json", + "style": "default", + "rsc": false, + "tsx": true, + "tailwind": { + "config": "tailwind.config.js", + "css": "src/styles/globals.css", + "baseColor": "slate", + "cssVariables": true + }, + "aliases": { + "components": "@/components", + "utils": "@/lib/utils" + } +} diff --git a/link-shortner/next.config.mjs b/link-shortner/next.config.mjs new file mode 100644 index 0000000..d6bed7a --- /dev/null +++ b/link-shortner/next.config.mjs @@ -0,0 +1,22 @@ +/** + * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful + * for Docker builds. + */ +await import("./src/env.mjs"); + +/** @type {import("next").NextConfig} */ +const config = { + reactStrictMode: true, + // pageExtensions:[''] + /** + * If you are using `appDir` then you must comment the below `i18n` config out. + * + * @see https://github.com/vercel/next.js/issues/41980 + */ + i18n: { + locales: ["en"], + defaultLocale: "en", + }, +}; + +export default config; diff --git a/link-shortner/package.json b/link-shortner/package.json new file mode 100644 index 0000000..41561a8 --- /dev/null +++ b/link-shortner/package.json @@ -0,0 +1,54 @@ +{ + "name": "linkr", + "version": "0.1.0", + "private": true, + "scripts": { + "build": "next build", + "db:push": "prisma db push", + "dev": "next dev", + "postinstall": "prisma generate", + "lint": "next lint", + "start": "next start" + }, + "dependencies": { + "@prisma/client": "^5.1.1", + "@radix-ui/react-slot": "^1.0.2", + "@t3-oss/env-nextjs": "^0.6.0", + "@tanstack/react-query": "^4.32.6", + "@trpc/client": "^10.37.1", + "@trpc/next": "^10.37.1", + "@trpc/react-query": "^10.37.1", + "@trpc/server": "^10.37.1", + "class-variance-authority": "^0.7.0", + "clsx": "^2.0.0", + "lucide-react": "^0.284.0", + "next": "^13.4.19", + "react": "18.2.0", + "react-dom": "18.2.0", + "react-hot-toast": "^2.4.1", + "superjson": "^1.13.1", + "tailwind-merge": "^1.14.0", + "tailwindcss-animate": "^1.0.7", + "zod": "^3.21.4" + }, + "devDependencies": { + "@types/eslint": "^8.44.2", + "@types/node": "^18.16.0", + "@types/react": "^18.2.20", + "@types/react-dom": "^18.2.7", + "@typescript-eslint/eslint-plugin": "^6.3.0", + "@typescript-eslint/parser": "^6.3.0", + "autoprefixer": "^10.4.14", + "eslint": "^8.47.0", + "eslint-config-next": "^13.4.19", + "postcss": "^8.4.27", + "prettier": "^3.0.0", + "prettier-plugin-tailwindcss": "^0.5.1", + "prisma": "^5.1.1", + "tailwindcss": "^3.3.3", + "typescript": "^5.1.6" + }, + "ct3aMetadata": { + "initVersion": "7.20.2" + } +} diff --git a/link-shortner/postcss.config.cjs b/link-shortner/postcss.config.cjs new file mode 100644 index 0000000..e305dd9 --- /dev/null +++ b/link-shortner/postcss.config.cjs @@ -0,0 +1,8 @@ +const config = { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; + +module.exports = config; diff --git a/link-shortner/prettier.config.mjs b/link-shortner/prettier.config.mjs new file mode 100644 index 0000000..2d2fa4c --- /dev/null +++ b/link-shortner/prettier.config.mjs @@ -0,0 +1,6 @@ +/** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').options} */ +const config = { + plugins: ["prettier-plugin-tailwindcss"], +}; + +export default config; diff --git a/link-shortner/prisma/schema.prisma b/link-shortner/prisma/schema.prisma new file mode 100644 index 0000000..cc669f3 --- /dev/null +++ b/link-shortner/prisma/schema.prisma @@ -0,0 +1,21 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "mysql" + url = env("DATABASE_URL") +} + +model Link { + id Int @id @default(autoincrement()) + slug String @unique + url String @db.LongText + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + @@index([slug]) +} diff --git a/link-shortner/public/favicon.ico b/link-shortner/public/favicon.ico new file mode 100644 index 0000000..60c702a Binary files /dev/null and b/link-shortner/public/favicon.ico differ diff --git a/link-shortner/src/components/ui/button.tsx b/link-shortner/src/components/ui/button.tsx new file mode 100644 index 0000000..35d444f --- /dev/null +++ b/link-shortner/src/components/ui/button.tsx @@ -0,0 +1,56 @@ +import * as React from "react"; +import { Slot } from "@radix-ui/react-slot"; +import { cva, type VariantProps } from "class-variance-authority"; + +import { cn } from "~/lib/utils"; + +const buttonVariants = cva( + "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", + { + variants: { + variant: { + default: "bg-primary text-primary-foreground hover:bg-primary/90", + destructive: + "bg-destructive text-destructive-foreground hover:bg-destructive/90", + outline: + "border border-input bg-background hover:bg-accent hover:text-accent-foreground", + secondary: + "bg-secondary text-secondary-foreground hover:bg-secondary/80", + ghost: "hover:bg-accent hover:text-accent-foreground", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-10 px-4 py-2", + sm: "h-9 rounded-md px-3", + lg: "h-11 rounded-md px-8", + icon: "h-10 w-10", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, + }, +); + +export interface ButtonProps + extends React.ButtonHTMLAttributes, + VariantProps { + asChild?: boolean; +} + +const Button = React.forwardRef( + ({ className, variant, size, asChild = false, ...props }, ref) => { + const Comp = asChild ? Slot : "button"; + return ( + + ); + }, +); +Button.displayName = "Button"; + +export { Button, buttonVariants }; diff --git a/link-shortner/src/components/ui/input.tsx b/link-shortner/src/components/ui/input.tsx new file mode 100644 index 0000000..8ac4ede --- /dev/null +++ b/link-shortner/src/components/ui/input.tsx @@ -0,0 +1,25 @@ +import * as React from "react"; + +import { cn } from "~/lib/utils"; + +export interface InputProps + extends React.InputHTMLAttributes {} + +const Input = React.forwardRef( + ({ className, type, ...props }, ref) => { + return ( + + ); + }, +); +Input.displayName = "Input"; + +export { Input }; diff --git a/link-shortner/src/env.mjs b/link-shortner/src/env.mjs new file mode 100644 index 0000000..b829852 --- /dev/null +++ b/link-shortner/src/env.mjs @@ -0,0 +1,45 @@ +import { createEnv } from "@t3-oss/env-nextjs"; +import { z } from "zod"; + +export const env = createEnv({ + /** + * Specify your server-side environment variables schema here. This way you can ensure the app + * isn't built with invalid env vars. + */ + server: { + DATABASE_URL: z + .string() + .url() + .refine( + (str) => !str.includes("YOUR_MYSQL_URL_HERE"), + "You forgot to change the default URL", + ), + NODE_ENV: z + .enum(["development", "test", "production"]) + .default("development"), + }, + + /** + * Specify your client-side environment variables schema here. This way you can ensure the app + * isn't built with invalid env vars. To expose them to the client, prefix them with + * `NEXT_PUBLIC_`. + */ + client: { + // NEXT_PUBLIC_CLIENTVAR: z.string().min(1), + }, + + /** + * You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g. + * middlewares) or client-side so we need to destruct manually. + */ + runtimeEnv: { + DATABASE_URL: process.env.DATABASE_URL, + NODE_ENV: process.env.NODE_ENV, + // NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR, + }, + /** + * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially + * useful for Docker builds. + */ + skipValidation: !!process.env.SKIP_ENV_VALIDATION, +}); diff --git a/link-shortner/src/lib/utils.ts b/link-shortner/src/lib/utils.ts new file mode 100644 index 0000000..365058c --- /dev/null +++ b/link-shortner/src/lib/utils.ts @@ -0,0 +1,6 @@ +import { type ClassValue, clsx } from "clsx"; +import { twMerge } from "tailwind-merge"; + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)); +} diff --git a/link-shortner/src/middleware.ts b/link-shortner/src/middleware.ts new file mode 100644 index 0000000..b31523c --- /dev/null +++ b/link-shortner/src/middleware.ts @@ -0,0 +1,16 @@ +import { Link } from "@prisma/client"; +import { NextResponse } from "next/server"; +import { NextRequest } from "next/server"; + +// This function can be marked `async` if using `await` inside +export async function middleware(request: NextRequest) { + const slug = request.nextUrl.pathname.split("/").pop(); + const link: Link = await ( + await fetch(`${request.nextUrl.origin}/api/${slug}`) + ).json(); + return NextResponse.redirect(link.url); +} + +export const config = { + matcher: ["/r/:slug*"], +}; diff --git a/link-shortner/src/pages/404.tsx b/link-shortner/src/pages/404.tsx new file mode 100644 index 0000000..cad1702 --- /dev/null +++ b/link-shortner/src/pages/404.tsx @@ -0,0 +1,3 @@ +export default function Custom404() { + return

404 - Page Not Found

; +} diff --git a/link-shortner/src/pages/_app.tsx b/link-shortner/src/pages/_app.tsx new file mode 100644 index 0000000..93cb393 --- /dev/null +++ b/link-shortner/src/pages/_app.tsx @@ -0,0 +1,18 @@ +import { type AppType } from "next/app"; + +import { api } from "~/utils/api"; + +import "~/styles/globals.css"; + +import { Toaster } from "react-hot-toast"; + +const MyApp: AppType = ({ Component, pageProps }) => { + return ( + <> + + + + ); +}; + +export default api.withTRPC(MyApp); diff --git a/link-shortner/src/pages/api/[slug].ts b/link-shortner/src/pages/api/[slug].ts new file mode 100644 index 0000000..7a3882c --- /dev/null +++ b/link-shortner/src/pages/api/[slug].ts @@ -0,0 +1,16 @@ +import { NextApiRequest, NextApiResponse } from "next"; +import { db } from "~/server/db"; + +export default async function getSlug( + req: NextApiRequest, + res: NextApiResponse, +) { + const slug = req.query.slug; + + const link = await db.link.findUnique({ where: { slug: slug as string } }); + if (link == null) { + console.log("nonono"); + res.status(404).send({ message: "not found" }); + } + res.send(link); +} diff --git a/link-shortner/src/pages/api/trpc/[trpc].ts b/link-shortner/src/pages/api/trpc/[trpc].ts new file mode 100644 index 0000000..634df1d --- /dev/null +++ b/link-shortner/src/pages/api/trpc/[trpc].ts @@ -0,0 +1,19 @@ +import { createNextApiHandler } from "@trpc/server/adapters/next"; + +import { env } from "~/env.mjs"; +import { appRouter } from "~/server/api/root"; +import { createTRPCContext } from "~/server/api/trpc"; + +// export API handler +export default createNextApiHandler({ + router: appRouter, + createContext: createTRPCContext, + onError: + env.NODE_ENV === "development" + ? ({ path, error }) => { + console.error( + `❌ tRPC failed on ${path ?? ""}: ${error.message}`, + ); + } + : undefined, +}); diff --git a/link-shortner/src/pages/index.tsx b/link-shortner/src/pages/index.tsx new file mode 100644 index 0000000..23cc2e1 --- /dev/null +++ b/link-shortner/src/pages/index.tsx @@ -0,0 +1,75 @@ +import { Button } from "~/components/ui/button"; +import Head from "next/head"; +import toast from "react-hot-toast"; +import Link from "next/link"; +import { Input } from "~/components/ui/input"; + +import { api } from "~/utils/api"; +import { useState } from "react"; + +export default function Home() { + const saveAlink = api.example.saveALink.useMutation(); + const [link, setLink] = useState("https://prabincankod.me"); + const [slug, setSlug] = useState("prabincankod"); + return ( + <> + + Linkr + + + + +
+
+
+ https://linkr.prasu.co/r/ + setSlug(e.target.value)} + /> + {/* */} + + +
+
+ Link + setLink(e.target.value)} + type="url" + placeholder="https://google.com" + className="my-1 block w-full rounded-md border border-slate-300 bg-white p-2 text-black placeholder-slate-400 shadow-sm focus:border-pink-500 focus:outline-none focus:ring-1 focus:ring-pink-500 sm:text-sm" + /> +
+ +
+
+ + ); +} diff --git a/link-shortner/src/server/api/root.ts b/link-shortner/src/server/api/root.ts new file mode 100644 index 0000000..7caea0f --- /dev/null +++ b/link-shortner/src/server/api/root.ts @@ -0,0 +1,14 @@ +import { exampleRouter } from "~/server/api/routers/example"; +import { createTRPCRouter } from "~/server/api/trpc"; + +/** + * This is the primary router for your server. + * + * All routers added in /api/routers should be manually added here. + */ +export const appRouter = createTRPCRouter({ + example: exampleRouter, +}); + +// export type definition of API +export type AppRouter = typeof appRouter; diff --git a/link-shortner/src/server/api/routers/example.ts b/link-shortner/src/server/api/routers/example.ts new file mode 100644 index 0000000..336e785 --- /dev/null +++ b/link-shortner/src/server/api/routers/example.ts @@ -0,0 +1,27 @@ +import { + PrismaClientKnownRequestError, + PrismaClientUnknownRequestError, +} from "@prisma/client/runtime/library"; +import { z } from "zod"; + +import { createTRPCRouter, publicProcedure } from "~/server/api/trpc"; + +export const exampleRouter = createTRPCRouter({ + saveALink: publicProcedure + .input(z.object({ link: z.string().url(), slug: z.string() })) + .mutation(async ({ ctx, input }) => { + try { + const link = await ctx.db.link.create({ + data: { slug: input.slug, url: input.link }, + }); + + return { + message: "link created successfully", + }; + } catch (e) { + if (e instanceof PrismaClientKnownRequestError) { + throw e; + } + } + }), +}); diff --git a/link-shortner/src/server/api/trpc.ts b/link-shortner/src/server/api/trpc.ts new file mode 100644 index 0000000..dc3b40b --- /dev/null +++ b/link-shortner/src/server/api/trpc.ts @@ -0,0 +1,95 @@ +/** + * YOU PROBABLY DON'T NEED TO EDIT THIS FILE, UNLESS: + * 1. You want to modify request context (see Part 1). + * 2. You want to create a new middleware or type of procedure (see Part 3). + * + * TL;DR - This is where all the tRPC server stuff is created and plugged in. The pieces you will + * need to use are documented accordingly near the end. + */ +import { initTRPC } from "@trpc/server"; +import { type CreateNextContextOptions } from "@trpc/server/adapters/next"; +import superjson from "superjson"; +import { ZodError } from "zod"; + +import { db } from "~/server/db"; + +/** + * 1. CONTEXT + * + * This section defines the "contexts" that are available in the backend API. + * + * These allow you to access things when processing a request, like the database, the session, etc. + */ + +type CreateContextOptions = Record; + +/** + * This helper generates the "internals" for a tRPC context. If you need to use it, you can export + * it from here. + * + * Examples of things you may need it for: + * - testing, so we don't have to mock Next.js' req/res + * - tRPC's `createSSGHelpers`, where we don't have req/res + * + * @see https://create.t3.gg/en/usage/trpc#-serverapitrpcts + */ +const createInnerTRPCContext = (_opts: CreateContextOptions) => { + return { + db, + }; +}; + +/** + * This is the actual context you will use in your router. It will be used to process every request + * that goes through your tRPC endpoint. + * + * @see https://trpc.io/docs/context + */ +export const createTRPCContext = (_opts: CreateNextContextOptions) => { + return createInnerTRPCContext({}); +}; + +/** + * 2. INITIALIZATION + * + * This is where the tRPC API is initialized, connecting the context and transformer. We also parse + * ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation + * errors on the backend. + */ + +const t = initTRPC.context().create({ + transformer: superjson, + errorFormatter({ shape, error }) { + return { + ...shape, + data: { + ...shape.data, + zodError: + error.cause instanceof ZodError ? error.cause.flatten() : null, + }, + }; + }, +}); + +/** + * 3. ROUTER & PROCEDURE (THE IMPORTANT BIT) + * + * These are the pieces you use to build your tRPC API. You should import these a lot in the + * "/src/server/api/routers" directory. + */ + +/** + * This is how you create new routers and sub-routers in your tRPC API. + * + * @see https://trpc.io/docs/router + */ +export const createTRPCRouter = t.router; + +/** + * Public (unauthenticated) procedure + * + * This is the base piece you use to build new queries and mutations on your tRPC API. It does not + * guarantee that a user querying is authorized, but you can still access user session data if they + * are logged in. + */ +export const publicProcedure = t.procedure; diff --git a/link-shortner/src/server/db.ts b/link-shortner/src/server/db.ts new file mode 100644 index 0000000..a4753ca --- /dev/null +++ b/link-shortner/src/server/db.ts @@ -0,0 +1,16 @@ +import { PrismaClient } from "@prisma/client"; + +import { env } from "~/env.mjs"; + +const globalForPrisma = globalThis as unknown as { + prisma: PrismaClient | undefined; +}; + +export const db = + globalForPrisma.prisma ?? + new PrismaClient({ + log: + env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"], + }); + +if (env.NODE_ENV !== "production") globalForPrisma.prisma = db; diff --git a/link-shortner/src/styles/globals.css b/link-shortner/src/styles/globals.css new file mode 100644 index 0000000..1adec05 --- /dev/null +++ b/link-shortner/src/styles/globals.css @@ -0,0 +1,59 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +@layer base { + :root { + --background: 0 0% 100%; + --foreground: 240 10% 3.9%; + --card: 0 0% 100%; + --card-foreground: 240 10% 3.9%; + --popover: 0 0% 100%; + --popover-foreground: 240 10% 3.9%; + --primary: 346.8 77.2% 49.8%; + --primary-foreground: 355.7 100% 97.3%; + --secondary: 240 4.8% 95.9%; + --secondary-foreground: 240 5.9% 10%; + --muted: 240 4.8% 95.9%; + --muted-foreground: 240 3.8% 46.1%; + --accent: 240 4.8% 95.9%; + --accent-foreground: 240 5.9% 10%; + --destructive: 0 84.2% 60.2%; + --destructive-foreground: 0 0% 98%; + --border: 240 5.9% 90%; + --input: 240 5.9% 90%; + --ring: 346.8 77.2% 49.8%; + --radius: 0.3rem; + } + + .dark { + --background: 20 14.3% 4.1%; + --foreground: 0 0% 95%; + --card: 24 9.8% 10%; + --card-foreground: 0 0% 95%; + --popover: 0 0% 9%; + --popover-foreground: 0 0% 95%; + --primary: 346.8 77.2% 49.8%; + --primary-foreground: 355.7 100% 97.3%; + --secondary: 240 3.7% 15.9%; + --secondary-foreground: 0 0% 98%; + --muted: 0 0% 15%; + --muted-foreground: 240 5% 64.9%; + --accent: 12 6.5% 15.1%; + --accent-foreground: 0 0% 98%; + --destructive: 0 62.8% 30.6%; + --destructive-foreground: 0 85.7% 97.3%; + --border: 240 3.7% 15.9%; + --input: 240 3.7% 15.9%; + --ring: 346.8 77.2% 49.8%; + } +} + +@layer base { + * { + @apply border-border; + } + body { + @apply bg-background text-foreground; + } +} diff --git a/link-shortner/src/utils/api.ts b/link-shortner/src/utils/api.ts new file mode 100644 index 0000000..f4f4ad5 --- /dev/null +++ b/link-shortner/src/utils/api.ts @@ -0,0 +1,68 @@ +/** + * This is the client-side entrypoint for your tRPC API. It is used to create the `api` object which + * contains the Next.js App-wrapper, as well as your type-safe React Query hooks. + * + * We also create a few inference helpers for input and output types. + */ +import { httpBatchLink, loggerLink } from "@trpc/client"; +import { createTRPCNext } from "@trpc/next"; +import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server"; +import superjson from "superjson"; + +import { type AppRouter } from "~/server/api/root"; + +const getBaseUrl = () => { + if (typeof window !== "undefined") return ""; // browser should use relative url + if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`; // SSR should use vercel url + return `http://localhost:${process.env.PORT ?? 3000}`; // dev SSR should use localhost +}; + +/** A set of type-safe react-query hooks for your tRPC API. */ +export const api = createTRPCNext({ + config() { + return { + /** + * Transformer used for data de-serialization from the server. + * + * @see https://trpc.io/docs/data-transformers + */ + transformer: superjson, + + /** + * Links used to determine request flow from client to server. + * + * @see https://trpc.io/docs/links + */ + links: [ + loggerLink({ + enabled: (opts) => + process.env.NODE_ENV === "development" || + (opts.direction === "down" && opts.result instanceof Error), + }), + httpBatchLink({ + url: `${getBaseUrl()}/api/trpc`, + }), + ], + }; + }, + /** + * Whether tRPC should await queries when server rendering pages. + * + * @see https://trpc.io/docs/nextjs#ssr-boolean-default-false + */ + ssr: false, +}); + +/** + * Inference helper for inputs. + * + * @example type HelloInput = RouterInputs['example']['hello'] + */ +export type RouterInputs = inferRouterInputs; + +/** + * Inference helper for outputs. + * + * @example type HelloOutput = RouterOutputs['example']['hello'] + */ +export type RouterOutputs = inferRouterOutputs; diff --git a/link-shortner/tailwind.config.js b/link-shortner/tailwind.config.js new file mode 100644 index 0000000..c05b2ff --- /dev/null +++ b/link-shortner/tailwind.config.js @@ -0,0 +1,76 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + darkMode: ["class"], + content: [ + "./pages/**/*.{ts,tsx}", + "./components/**/*.{ts,tsx}", + "./app/**/*.{ts,tsx}", + "./src/**/*.{ts,tsx}", + ], + theme: { + container: { + center: true, + padding: "2rem", + screens: { + "2xl": "1400px", + }, + }, + extend: { + colors: { + border: "hsl(var(--border))", + input: "hsl(var(--input))", + ring: "hsl(var(--ring))", + background: "hsl(var(--background))", + foreground: "hsl(var(--foreground))", + primary: { + DEFAULT: "hsl(var(--primary))", + foreground: "hsl(var(--primary-foreground))", + }, + secondary: { + DEFAULT: "hsl(var(--secondary))", + foreground: "hsl(var(--secondary-foreground))", + }, + destructive: { + DEFAULT: "hsl(var(--destructive))", + foreground: "hsl(var(--destructive-foreground))", + }, + muted: { + DEFAULT: "hsl(var(--muted))", + foreground: "hsl(var(--muted-foreground))", + }, + accent: { + DEFAULT: "hsl(var(--accent))", + foreground: "hsl(var(--accent-foreground))", + }, + popover: { + DEFAULT: "hsl(var(--popover))", + foreground: "hsl(var(--popover-foreground))", + }, + card: { + DEFAULT: "hsl(var(--card))", + foreground: "hsl(var(--card-foreground))", + }, + }, + borderRadius: { + lg: "var(--radius)", + md: "calc(var(--radius) - 2px)", + sm: "calc(var(--radius) - 4px)", + }, + keyframes: { + "accordion-down": { + from: { height: 0 }, + to: { height: "var(--radix-accordion-content-height)" }, + }, + "accordion-up": { + from: { height: "var(--radix-accordion-content-height)" }, + to: { height: 0 }, + }, + }, + animation: { + "accordion-down": "accordion-down 0.2s ease-out", + "accordion-up": "accordion-up 0.2s ease-out", + }, + }, + }, + plugins: [require("tailwindcss-animate")], +}; diff --git a/link-shortner/tailwind.config.ts b/link-shortner/tailwind.config.ts new file mode 100644 index 0000000..d4d3fa2 --- /dev/null +++ b/link-shortner/tailwind.config.ts @@ -0,0 +1,9 @@ +import { type Config } from "tailwindcss"; + +export default { + content: ["./src/**/*.{js,ts,jsx,tsx}"], + theme: { + extend: {}, + }, + plugins: [], +} satisfies Config; diff --git a/link-shortner/tsconfig.json b/link-shortner/tsconfig.json new file mode 100644 index 0000000..07a0fd5 --- /dev/null +++ b/link-shortner/tsconfig.json @@ -0,0 +1,34 @@ +{ + "compilerOptions": { + "target": "es2017", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "checkJs": true, + "skipLibCheck": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "noUncheckedIndexedAccess": true, + "baseUrl": ".", + "paths": { + "~/*": ["./src/*"] + } + }, + "include": [ + ".eslintrc.cjs", + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + "**/*.cjs", + "**/*.mjs", + "**/middleware.ts" + ], + "exclude": ["node_modules"] +}