url-projectindex.ts5 matches
1import { ActionFunctionArgs, LoaderFunctionArgs } from "npm:react-router";
2import Layout from "./layout.tsx";
3import Home from "./home.tsx";
15// imports the correct one to avoid putting the server code in client
16// bundles
17async loader(args: LoaderFunctionArgs) {
18let mod = await (isServer
19? import("./layout.server.ts")
23// same with the action, you'll probably want to abstract this kind of stuff
24// in a createRoute() kind of thing
25async action(args: ActionFunctionArgs) {
26let mod = await (isServer
27? import("./layout.server.ts")
35Component: Home,
36ErrorBoundary: Home.ErrorBoundary,
37async loader(args: LoaderFunctionArgs) {
38// Fetch recent URLs
39const response = await fetch(new URL("/api/recent", args.request.url));
49Component: CreateShortUrl,
50ErrorBoundary: CreateShortUrl.ErrorBoundary,
51async action(args: ActionFunctionArgs) {
52const formData = await args.request.formData();
53const longUrl = formData.get("longUrl");
url-projectserver.tsx1 match
9} from "./backend/database/queries.ts";
1011export default async function(request: Request) {
12const url = new URL(request.url);
13const path = url.pathname;
url-projectabout.tsx1 match
2import { useLoaderData } from "npm:react-router";
34export default function About() {
5const data = useLoaderData() as { message: string };
6
url-projectindex.ts1 match
11* Main server handler for the URL shortener application
12*/
13export default async function(request: Request): Promise<Response> {
14// Initialize database on each request
15await initializeDatabase(import.meta.url);
url-projectREADME.md1 match
3This directory contains code that is shared between the frontend and backend.
45- `utils.ts` - Utility functions and shared types
2import React, { useState } from "https://esm.sh/react@18.2.0";
34export function CreateShortUrl() {
5const [longUrl, setLongUrl] = useState("");
6const [isSubmitting, setIsSubmitting] = useState(false);
url-projectHome.tsx1 match
3import { ShortUrl } from "../../shared/utils.ts";
45export function Home() {
6const [recentUrls, setRecentUrls] = useState<ShortUrl[]>([]);
7const [isLoading, setIsLoading] = useState(true);
url-projectApp.tsx1 match
4import { CreateShortUrl } from "./CreateShortUrl.tsx";
56export function App() {
7const [currentRoute, setCurrentRoute] = useState("/");
8
url-projectentry.server.tsx1 match
7let { query, dataRoutes } = createStaticHandler(routes);
89export async function handler(request: Request) {
10// 1. run actions/loaders to get the routing context with `query`
11let context = await query(request);
url-projectabout.loader.ts1 match
1import { data } from "npm:react-router";
23export default async function load() {
4await new Promise(resolve => setTimeout(resolve, 200));
5