From ac459f2c34f2e1a6959f59fc617b217947ce7e5e Mon Sep 17 00:00:00 2001 From: Tatsuto YAMAMOTO Date: Sat, 5 Sep 2026 19:23:06 +0900 Subject: [PATCH 1/4] refactor: consolidate account API client --- app/lib/account.ts | 93 --------------------------- app/lib/api/account.ts | 40 +++++------- app/lib/cloudflareContext.ts | 7 ++ app/routes/_index.tsx | 8 ++- app/routes/accounts.$id._index.tsx | 10 +-- app/routes/accounts.$id.follower.tsx | 8 ++- app/routes/accounts.$id.following.tsx | 8 ++- 7 files changed, 43 insertions(+), 131 deletions(-) delete mode 100644 app/lib/account.ts diff --git a/app/lib/account.ts b/app/lib/account.ts deleted file mode 100644 index 8a0572a..0000000 --- a/app/lib/account.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { - getV0AccountsIdentifier, - getV0TimelineAccountsId, -} from "@pulsate-dev/exp-api-types"; - -import type { TimelineResponse } from "~/lib/api/timeline"; - -import { apiOptions, parseApiErrorMessage } from "./api/client"; - -export interface AccountResponse { - id: string; - name: string; - nickname: string; - bio: string; - avatar: string; - header: string; - followed_count: number; - following_count: number; - note_count: number; -} - -export const account = async ( - identifier: string, - token: string | undefined, - basePath: string -): Promise => { - try { - const { data, error } = await getV0AccountsIdentifier({ - ...apiOptions( - basePath, - token, - `/v0/accounts/${encodeURIComponent(identifier)}` - ), - path: { identifier }, - }); - if (error || !data) { - return { error: error ? parseApiErrorMessage(error) : "failed to fetch" }; - } - return { - id: data.id, - name: data.name, - nickname: data.nickname, - bio: data.bio, - avatar: data.avatar, - header: data.header, - followed_count: data.followed_count, - following_count: data.following_count, - note_count: data.note_count, - }; - } catch { - return { error: "unknown error" }; - } -}; - -export const accountTimeline = async ( - id: string, - token: string | undefined, - basePath: string, - beforeID?: string, - afterID?: string -): Promise => { - try { - const { data, error } = await getV0TimelineAccountsId({ - ...apiOptions( - basePath, - token, - `/v0/timeline/accounts/${encodeURIComponent(id)}` - ), - path: { id }, - query: beforeID - ? { before_id: beforeID } - : afterID - ? { after_id: afterID } - : undefined, - }); - if (error || !data) { - return { error: parseApiErrorMessage(error) }; - } - const timelineNotes = data.map( - (note) => - ({ - ...note, - created_at: new Date(note.created_at), - visibility: note.visibility as TimelineResponse["visibility"], - }) satisfies TimelineResponse - ); - return afterID - ? timelineNotes.filter((note) => note.id !== afterID).reverse() - : timelineNotes; - } catch { - return { error: "unknown error" }; - } -}; diff --git a/app/lib/api/account.ts b/app/lib/api/account.ts index 40cf167..96f8496 100644 --- a/app/lib/api/account.ts +++ b/app/lib/api/account.ts @@ -74,7 +74,8 @@ export const accountTimeline = async ( id: string, token: string | undefined, basePath: string, - beforeID?: string + beforeID?: string, + afterID?: string ): Promise => { try { const { data: response, error } = await getV0TimelineAccountsId({ @@ -84,38 +85,27 @@ export const accountTimeline = async ( `/v0/timeline/accounts/${encodeURIComponent(id)}` ), path: { id }, - query: beforeID ? { before_id: beforeID } : undefined, + query: beforeID + ? { before_id: beforeID } + : afterID + ? { after_id: afterID } + : undefined, }); if (error || !response) { return { error: parseApiErrorMessage(error) }; } - return response.map( - (item) => + const timelineNotes = response.map( + (note) => ({ - id: item.id, - content: item.content, - contents_warning_comment: item.contents_warning_comment, - visibility: item.visibility as "PUBLIC" | "HOME" | "FOLLOWERS", - created_at: new Date(item.created_at), - author: { - id: item.author.id, - name: item.author.name, - display_name: item.author.display_name, - bio: item.author.bio, - avatar: item.author.avatar, - header: item.author.header, - followed_count: item.author.followed_count, - following_count: item.author.following_count, - }, - reactions: item.reactions.map( - (reaction): TimelineResponse["reactions"][number] => ({ - emoji: reaction.emoji, - reacted_by: reaction.reacted_by, - }) - ), + ...note, + created_at: new Date(note.created_at), + visibility: note.visibility as TimelineResponse["visibility"], }) satisfies TimelineResponse ); + return afterID + ? timelineNotes.filter((note) => note.id !== afterID).reverse() + : timelineNotes; } catch { return { error: "unknown error" }; } diff --git a/app/lib/cloudflareContext.ts b/app/lib/cloudflareContext.ts index dd41f42..293d365 100644 --- a/app/lib/cloudflareContext.ts +++ b/app/lib/cloudflareContext.ts @@ -4,3 +4,10 @@ export const cloudflareContext = createContext<{ env: Env; ctx: ExecutionContext; }>(); + +export const requireApiBasePath = (basePath: string | undefined): string => { + if (!basePath) { + throw new Error("API_BASE_URL env was not configured"); + } + return basePath; +}; diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 57acaae..8ba335a 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -1,9 +1,9 @@ import type { LoaderFunctionArgs } from "react-router"; import { Link, useLoaderData } from "react-router"; -import { account } from "~/lib/account"; +import { account } from "~/lib/api/account"; import { getToken } from "~/lib/api/getToken"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; import { parseToken } from "~/lib/parseToken"; export const loader = async ({ @@ -21,7 +21,9 @@ export const loader = async ({ return { isLoggedIn: false }; } - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const accountDatum = await account(parsedToken.id, token, basePath); return { isLoggedIn: !("error" in accountDatum) }; }; diff --git a/app/routes/accounts.$id._index.tsx b/app/routes/accounts.$id._index.tsx index 216be15..fd0a4ad 100644 --- a/app/routes/accounts.$id._index.tsx +++ b/app/routes/accounts.$id._index.tsx @@ -6,8 +6,8 @@ import { FollowButton } from "~/components/followButton"; import { LoadMoreNoteButton } from "~/components/loadMoreNote"; import type { NoteProps } from "~/components/note"; import { Note } from "~/components/note"; -import type { AccountResponse } from "~/lib/account"; -import { account, accountTimeline } from "~/lib/account"; +import type { AccountResponse } from "~/lib/api/account"; +import { account, accountTimeline } from "~/lib/api/account"; import { getToken } from "~/lib/api/getToken"; import { loggedInAccount } from "~/lib/api/loggedInAccount"; import { fetchNote } from "~/lib/api/note"; @@ -16,7 +16,7 @@ import { type AccountRelationshipResponse, } from "~/lib/api/relationship"; import type { TimelineResponse } from "~/lib/api/timeline"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; import { defaultAccountAvatar } from "~/lib/defaultAccountImage"; import styles from "~/styles/account.module.css"; @@ -36,7 +36,9 @@ export const loader = async ({ originalNotes: TimelineResponse[]; } > => { - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const isLoggedIn = await getToken(request); if (!isLoggedIn.isLoggedIn) { diff --git a/app/routes/accounts.$id.follower.tsx b/app/routes/accounts.$id.follower.tsx index 4d7d392..ca73817 100644 --- a/app/routes/accounts.$id.follower.tsx +++ b/app/routes/accounts.$id.follower.tsx @@ -1,10 +1,10 @@ import { redirect, useLoaderData, type LoaderFunctionArgs } from "react-router"; import { FollowAccount } from "~/components/followAccount"; -import { account } from "~/lib/account"; +import { account } from "~/lib/api/account"; import { getFollowersList, type FollowerResponse } from "~/lib/api/followlist"; import { getToken } from "~/lib/api/getToken"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; export async function loader({ params, @@ -13,7 +13,9 @@ export async function loader({ }: LoaderFunctionArgs): Promise< { isSuccess: false } | { isSuccess: true; response: FollowerResponse[] } > { - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const isLoggedIn = await getToken(request); if (!isLoggedIn.isLoggedIn) { diff --git a/app/routes/accounts.$id.following.tsx b/app/routes/accounts.$id.following.tsx index 265bba7..54393f8 100644 --- a/app/routes/accounts.$id.following.tsx +++ b/app/routes/accounts.$id.following.tsx @@ -1,10 +1,10 @@ import { redirect, useLoaderData, type LoaderFunctionArgs } from "react-router"; import { FollowAccount } from "~/components/followAccount"; -import { account } from "~/lib/account"; +import { account } from "~/lib/api/account"; import { getFollowingList, type FollowingResponse } from "~/lib/api/followlist"; import { getToken } from "~/lib/api/getToken"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; export async function loader({ params, @@ -13,7 +13,9 @@ export async function loader({ }: LoaderFunctionArgs): Promise< { isSuccess: false } | { isSuccess: true; response: FollowingResponse[] } > { - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const isLoggedIn = await getToken(request); if (!isLoggedIn.isLoggedIn) { From 597a4b5491430723b426a394d70ce147c4bcaab6 Mon Sep 17 00:00:00 2001 From: Tatsuto YAMAMOTO Date: Sat, 5 Sep 2026 19:23:29 +0900 Subject: [PATCH 2/4] fix: validate API base URL --- app/root.tsx | 6 ++++-- app/routes/accounts.$id.edit.tsx | 10 +++++++--- app/routes/api.follow.ts | 6 ++++-- app/routes/api.notes.ts | 6 ++++-- app/routes/api.reaction.ts | 6 ++++-- app/routes/api.renote.ts | 6 ++++-- app/routes/login.tsx | 6 ++++-- app/routes/signup.verify.tsx | 6 ++++-- app/routes/timeline.tsx | 6 ++++-- 9 files changed, 39 insertions(+), 19 deletions(-) diff --git a/app/root.tsx b/app/root.tsx index 126a08a..7b02092 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -12,7 +12,7 @@ import { loggedInAccount, type LoggedInAccountResponse, } from "~/lib/api/loggedInAccount"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; import styles from "~/root.module.css"; @@ -20,7 +20,9 @@ export async function loader({ request, context, }: LoaderFunctionArgs): Promise { - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); return loggedInAccount(request, basePath); } diff --git a/app/routes/accounts.$id.edit.tsx b/app/routes/accounts.$id.edit.tsx index afc2fb9..392038c 100644 --- a/app/routes/accounts.$id.edit.tsx +++ b/app/routes/accounts.$id.edit.tsx @@ -8,7 +8,7 @@ import { Form, redirect, useActionData, useLoaderData } from "react-router"; import { account, updateAccount } from "~/lib/api/account"; import { getToken } from "~/lib/api/getToken"; import { loggedInAccount } from "~/lib/api/loggedInAccount"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; const ERROR_MESSAGES = { invalidRequest: "Invalid request. Please try again.", @@ -45,7 +45,9 @@ export const loader = async ({ params, context, }: LoaderFunctionArgs): Promise => { - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const tokenData = await getToken(request); if (!tokenData.isLoggedIn) { @@ -85,7 +87,9 @@ export const action = async ({ params, context, }: ActionFunctionArgs): Promise => { - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const tokenData = await getToken(request); if (!tokenData.isLoggedIn) { diff --git a/app/routes/api.follow.ts b/app/routes/api.follow.ts index 6f9b5aa..b81aa8b 100644 --- a/app/routes/api.follow.ts +++ b/app/routes/api.follow.ts @@ -4,7 +4,7 @@ import { redirect } from "react-router"; import { followAccount, unfollowAccount } from "~/lib/api/follow"; import { getToken } from "~/lib/api/getToken"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -19,7 +19,9 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { try { const formData = await request.formData(); - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); switch (request.method) { case "POST": { diff --git a/app/routes/api.notes.ts b/app/routes/api.notes.ts index 4d25f4f..327eabd 100644 --- a/app/routes/api.notes.ts +++ b/app/routes/api.notes.ts @@ -5,7 +5,7 @@ import { redirect } from "react-router"; import { apiOptions, parseApiErrorMessage } from "~/lib/api/client"; import { getToken } from "~/lib/api/getToken"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -20,7 +20,9 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { try { const formData = await request.formData(); - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const { error } = await postV0Notes({ ...apiOptions(basePath, token), body: { diff --git a/app/routes/api.reaction.ts b/app/routes/api.reaction.ts index 30210f6..dd77e9f 100644 --- a/app/routes/api.reaction.ts +++ b/app/routes/api.reaction.ts @@ -8,7 +8,7 @@ import { redirect } from "react-router"; import { apiOptions } from "~/lib/api/client"; import { getToken } from "~/lib/api/getToken"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -22,7 +22,9 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { const token = isLoggedIn.token; const formData = await request.formData(); - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); switch (request.method) { case "POST": diff --git a/app/routes/api.renote.ts b/app/routes/api.renote.ts index 3277b33..34d6dca 100644 --- a/app/routes/api.renote.ts +++ b/app/routes/api.renote.ts @@ -4,7 +4,7 @@ import { redirect } from "react-router"; import { getToken } from "~/lib/api/getToken"; import { renote } from "~/lib/api/renote"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -24,7 +24,9 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { const formData = await request.formData(); const noteID = formData.get("noteID") as string; - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const result = await renote(basePath, token, noteID, { content: "", diff --git a/app/routes/login.tsx b/app/routes/login.tsx index 5032502..b60d078 100644 --- a/app/routes/login.tsx +++ b/app/routes/login.tsx @@ -2,7 +2,7 @@ import type { ActionFunctionArgs, MetaFunction } from "react-router"; import { Form, Link, redirect, useActionData } from "react-router"; import { accountCookie, login } from "~/lib/api/login"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; import styles from "~/components/login.module.css"; @@ -31,7 +31,9 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { const email = formData.get("email") as string; const passphrase = formData.get("passphrase") as string; - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const res = await login({ email, passphrase }, basePath); if ("error" in res) { const errorMessage = diff --git a/app/routes/signup.verify.tsx b/app/routes/signup.verify.tsx index efe6ea5..6600599 100644 --- a/app/routes/signup.verify.tsx +++ b/app/routes/signup.verify.tsx @@ -3,7 +3,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { Link, useLoaderData } from "react-router"; import { apiOptions } from "~/lib/api/client"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; import { logger } from "~/lib/logger"; export const loader = async ({ @@ -24,7 +24,9 @@ export const loader = async ({ } try { - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); if (basePath == null) { logger.error("API_BASE_URL env was not configured"); return { error: "Something went wrong" }; diff --git a/app/routes/timeline.tsx b/app/routes/timeline.tsx index aaf5057..dc3a3ac 100644 --- a/app/routes/timeline.tsx +++ b/app/routes/timeline.tsx @@ -10,7 +10,7 @@ import { accountCookie } from "~/lib/api/login"; import { fetchNote } from "~/lib/api/note"; import type { TimelineResponse, TimelineType } from "~/lib/api/timeline"; import { fetchTimeline } from "~/lib/api/timeline"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; import styles from "~/styles/timeline.module.css"; @@ -30,7 +30,9 @@ export const loader = async ({ timeline: TimelineType; } > => { - const basePath = context.get(cloudflareContext).env.API_BASE_URL; + const basePath = requireApiBasePath( + context.get(cloudflareContext).env.API_BASE_URL + ); const cookie = await accountCookie.parse(request.headers.get("Cookie")); if (!cookie) { From 35a8fbb6411443d570d204d085967eb17537a9b5 Mon Sep 17 00:00:00 2001 From: Tatsuto YAMAMOTO Date: Sat, 5 Sep 2026 21:30:32 +0900 Subject: [PATCH 3/4] fix: fallback API base URL --- app/lib/cloudflareContext.ts | 8 ++------ app/root.tsx | 4 ++-- app/routes/_index.tsx | 4 ++-- app/routes/accounts.$id._index.tsx | 4 ++-- app/routes/accounts.$id.edit.tsx | 6 +++--- app/routes/accounts.$id.follower.tsx | 4 ++-- app/routes/accounts.$id.following.tsx | 4 ++-- app/routes/api.follow.ts | 4 ++-- app/routes/api.notes.ts | 4 ++-- app/routes/api.reaction.ts | 4 ++-- app/routes/api.renote.ts | 4 ++-- app/routes/login.tsx | 4 ++-- app/routes/signup._index.tsx | 9 ++------- app/routes/signup.verify.tsx | 4 ++-- app/routes/timeline.tsx | 4 ++-- 15 files changed, 31 insertions(+), 40 deletions(-) diff --git a/app/lib/cloudflareContext.ts b/app/lib/cloudflareContext.ts index 293d365..f3d6188 100644 --- a/app/lib/cloudflareContext.ts +++ b/app/lib/cloudflareContext.ts @@ -5,9 +5,5 @@ export const cloudflareContext = createContext<{ ctx: ExecutionContext; }>(); -export const requireApiBasePath = (basePath: string | undefined): string => { - if (!basePath) { - throw new Error("API_BASE_URL env was not configured"); - } - return basePath; -}; +export const getApiBasePath = (basePath: string | undefined): string => + basePath ?? "http://localhost:3000"; diff --git a/app/root.tsx b/app/root.tsx index 7b02092..78172fa 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -12,7 +12,7 @@ import { loggedInAccount, type LoggedInAccountResponse, } from "~/lib/api/loggedInAccount"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; import styles from "~/root.module.css"; @@ -20,7 +20,7 @@ export async function loader({ request, context, }: LoaderFunctionArgs): Promise { - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); return loggedInAccount(request, basePath); diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 8ba335a..b9083a0 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -3,7 +3,7 @@ import { Link, useLoaderData } from "react-router"; import { account } from "~/lib/api/account"; import { getToken } from "~/lib/api/getToken"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; import { parseToken } from "~/lib/parseToken"; export const loader = async ({ @@ -21,7 +21,7 @@ export const loader = async ({ return { isLoggedIn: false }; } - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); const accountDatum = await account(parsedToken.id, token, basePath); diff --git a/app/routes/accounts.$id._index.tsx b/app/routes/accounts.$id._index.tsx index fd0a4ad..17a494a 100644 --- a/app/routes/accounts.$id._index.tsx +++ b/app/routes/accounts.$id._index.tsx @@ -16,7 +16,7 @@ import { type AccountRelationshipResponse, } from "~/lib/api/relationship"; import type { TimelineResponse } from "~/lib/api/timeline"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; import { defaultAccountAvatar } from "~/lib/defaultAccountImage"; import styles from "~/styles/account.module.css"; @@ -36,7 +36,7 @@ export const loader = async ({ originalNotes: TimelineResponse[]; } > => { - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); diff --git a/app/routes/accounts.$id.edit.tsx b/app/routes/accounts.$id.edit.tsx index 392038c..6f216b4 100644 --- a/app/routes/accounts.$id.edit.tsx +++ b/app/routes/accounts.$id.edit.tsx @@ -8,7 +8,7 @@ import { Form, redirect, useActionData, useLoaderData } from "react-router"; import { account, updateAccount } from "~/lib/api/account"; import { getToken } from "~/lib/api/getToken"; import { loggedInAccount } from "~/lib/api/loggedInAccount"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; const ERROR_MESSAGES = { invalidRequest: "Invalid request. Please try again.", @@ -45,7 +45,7 @@ export const loader = async ({ params, context, }: LoaderFunctionArgs): Promise => { - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); @@ -87,7 +87,7 @@ export const action = async ({ params, context, }: ActionFunctionArgs): Promise => { - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); diff --git a/app/routes/accounts.$id.follower.tsx b/app/routes/accounts.$id.follower.tsx index ca73817..b212d99 100644 --- a/app/routes/accounts.$id.follower.tsx +++ b/app/routes/accounts.$id.follower.tsx @@ -4,7 +4,7 @@ import { FollowAccount } from "~/components/followAccount"; import { account } from "~/lib/api/account"; import { getFollowersList, type FollowerResponse } from "~/lib/api/followlist"; import { getToken } from "~/lib/api/getToken"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; export async function loader({ params, @@ -13,7 +13,7 @@ export async function loader({ }: LoaderFunctionArgs): Promise< { isSuccess: false } | { isSuccess: true; response: FollowerResponse[] } > { - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); const isLoggedIn = await getToken(request); diff --git a/app/routes/accounts.$id.following.tsx b/app/routes/accounts.$id.following.tsx index 54393f8..b276db2 100644 --- a/app/routes/accounts.$id.following.tsx +++ b/app/routes/accounts.$id.following.tsx @@ -4,7 +4,7 @@ import { FollowAccount } from "~/components/followAccount"; import { account } from "~/lib/api/account"; import { getFollowingList, type FollowingResponse } from "~/lib/api/followlist"; import { getToken } from "~/lib/api/getToken"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; export async function loader({ params, @@ -13,7 +13,7 @@ export async function loader({ }: LoaderFunctionArgs): Promise< { isSuccess: false } | { isSuccess: true; response: FollowingResponse[] } > { - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); const isLoggedIn = await getToken(request); diff --git a/app/routes/api.follow.ts b/app/routes/api.follow.ts index b81aa8b..7c578f6 100644 --- a/app/routes/api.follow.ts +++ b/app/routes/api.follow.ts @@ -4,7 +4,7 @@ import { redirect } from "react-router"; import { followAccount, unfollowAccount } from "~/lib/api/follow"; import { getToken } from "~/lib/api/getToken"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -19,7 +19,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { try { const formData = await request.formData(); - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); diff --git a/app/routes/api.notes.ts b/app/routes/api.notes.ts index 327eabd..2d7a7ea 100644 --- a/app/routes/api.notes.ts +++ b/app/routes/api.notes.ts @@ -5,7 +5,7 @@ import { redirect } from "react-router"; import { apiOptions, parseApiErrorMessage } from "~/lib/api/client"; import { getToken } from "~/lib/api/getToken"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -20,7 +20,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { try { const formData = await request.formData(); - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); const { error } = await postV0Notes({ diff --git a/app/routes/api.reaction.ts b/app/routes/api.reaction.ts index dd77e9f..2236eb9 100644 --- a/app/routes/api.reaction.ts +++ b/app/routes/api.reaction.ts @@ -8,7 +8,7 @@ import { redirect } from "react-router"; import { apiOptions } from "~/lib/api/client"; import { getToken } from "~/lib/api/getToken"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -22,7 +22,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { const token = isLoggedIn.token; const formData = await request.formData(); - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); diff --git a/app/routes/api.renote.ts b/app/routes/api.renote.ts index 34d6dca..098d2f7 100644 --- a/app/routes/api.renote.ts +++ b/app/routes/api.renote.ts @@ -4,7 +4,7 @@ import { redirect } from "react-router"; import { getToken } from "~/lib/api/getToken"; import { renote } from "~/lib/api/renote"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -24,7 +24,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { const formData = await request.formData(); const noteID = formData.get("noteID") as string; - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); diff --git a/app/routes/login.tsx b/app/routes/login.tsx index b60d078..713f6c9 100644 --- a/app/routes/login.tsx +++ b/app/routes/login.tsx @@ -2,7 +2,7 @@ import type { ActionFunctionArgs, MetaFunction } from "react-router"; import { Form, Link, redirect, useActionData } from "react-router"; import { accountCookie, login } from "~/lib/api/login"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; import styles from "~/components/login.module.css"; @@ -31,7 +31,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { const email = formData.get("email") as string; const passphrase = formData.get("passphrase") as string; - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); const res = await login({ email, passphrase }, basePath); diff --git a/app/routes/signup._index.tsx b/app/routes/signup._index.tsx index 6c61739..2dc46a6 100644 --- a/app/routes/signup._index.tsx +++ b/app/routes/signup._index.tsx @@ -4,7 +4,7 @@ import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router"; import { Form, Link, redirect, useLoaderData } from "react-router"; import { apiOptions } from "~/lib/api/client"; -import { cloudflareContext } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; import { logger } from "~/lib/logger"; import styles from "~/components/signup.module.css"; @@ -21,13 +21,8 @@ export const action = async ({ try { const env = context.get(cloudflareContext).env; - if (env.API_BASE_URL == null) { - logger.error("API_BASE_URL env was not configured"); - return { error: "Something went wrong" }; - } - const { error } = await postV0Accounts({ - ...apiOptions(env.API_BASE_URL), + ...apiOptions(getApiBasePath(env.API_BASE_URL)), body: { name: `@${name}@${env.INSTANCE_FQDN}`, email, diff --git a/app/routes/signup.verify.tsx b/app/routes/signup.verify.tsx index 6600599..475d2e4 100644 --- a/app/routes/signup.verify.tsx +++ b/app/routes/signup.verify.tsx @@ -3,7 +3,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { Link, useLoaderData } from "react-router"; import { apiOptions } from "~/lib/api/client"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; import { logger } from "~/lib/logger"; export const loader = async ({ @@ -24,7 +24,7 @@ export const loader = async ({ } try { - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); if (basePath == null) { diff --git a/app/routes/timeline.tsx b/app/routes/timeline.tsx index dc3a3ac..5f4577d 100644 --- a/app/routes/timeline.tsx +++ b/app/routes/timeline.tsx @@ -10,7 +10,7 @@ import { accountCookie } from "~/lib/api/login"; import { fetchNote } from "~/lib/api/note"; import type { TimelineResponse, TimelineType } from "~/lib/api/timeline"; import { fetchTimeline } from "~/lib/api/timeline"; -import { cloudflareContext, requireApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; import styles from "~/styles/timeline.module.css"; @@ -30,7 +30,7 @@ export const loader = async ({ timeline: TimelineType; } > => { - const basePath = requireApiBasePath( + const basePath = getApiBasePath( context.get(cloudflareContext).env.API_BASE_URL ); From fbf3bc43f7149b6ea667e0726f135f6df03c89a7 Mon Sep 17 00:00:00 2001 From: Tatsuto YAMAMOTO Date: Sat, 5 Sep 2026 21:54:32 +0900 Subject: [PATCH 4/4] fix: define default worker environment variables --- app/lib/cloudflareContext.ts | 3 - app/root.tsx | 6 +- app/routes/_index.tsx | 6 +- app/routes/accounts.$id._index.tsx | 6 +- app/routes/accounts.$id.edit.tsx | 10 +-- app/routes/accounts.$id.follower.tsx | 6 +- app/routes/accounts.$id.following.tsx | 6 +- app/routes/api.follow.ts | 6 +- app/routes/api.notes.ts | 6 +- app/routes/api.reaction.ts | 6 +- app/routes/api.renote.ts | 6 +- app/routes/login.tsx | 6 +- app/routes/signup._index.tsx | 4 +- app/routes/signup.verify.tsx | 6 +- app/routes/timeline.tsx | 6 +- wrangler.jsonc | 106 +++++++++++++------------- 16 files changed, 84 insertions(+), 111 deletions(-) diff --git a/app/lib/cloudflareContext.ts b/app/lib/cloudflareContext.ts index f3d6188..dd41f42 100644 --- a/app/lib/cloudflareContext.ts +++ b/app/lib/cloudflareContext.ts @@ -4,6 +4,3 @@ export const cloudflareContext = createContext<{ env: Env; ctx: ExecutionContext; }>(); - -export const getApiBasePath = (basePath: string | undefined): string => - basePath ?? "http://localhost:3000"; diff --git a/app/root.tsx b/app/root.tsx index 78172fa..126a08a 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -12,7 +12,7 @@ import { loggedInAccount, type LoggedInAccountResponse, } from "~/lib/api/loggedInAccount"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; import styles from "~/root.module.css"; @@ -20,9 +20,7 @@ export async function loader({ request, context, }: LoaderFunctionArgs): Promise { - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; return loggedInAccount(request, basePath); } diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index b9083a0..49a1895 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -3,7 +3,7 @@ import { Link, useLoaderData } from "react-router"; import { account } from "~/lib/api/account"; import { getToken } from "~/lib/api/getToken"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; import { parseToken } from "~/lib/parseToken"; export const loader = async ({ @@ -21,9 +21,7 @@ export const loader = async ({ return { isLoggedIn: false }; } - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const accountDatum = await account(parsedToken.id, token, basePath); return { isLoggedIn: !("error" in accountDatum) }; }; diff --git a/app/routes/accounts.$id._index.tsx b/app/routes/accounts.$id._index.tsx index 17a494a..5db83b0 100644 --- a/app/routes/accounts.$id._index.tsx +++ b/app/routes/accounts.$id._index.tsx @@ -16,7 +16,7 @@ import { type AccountRelationshipResponse, } from "~/lib/api/relationship"; import type { TimelineResponse } from "~/lib/api/timeline"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; import { defaultAccountAvatar } from "~/lib/defaultAccountImage"; import styles from "~/styles/account.module.css"; @@ -36,9 +36,7 @@ export const loader = async ({ originalNotes: TimelineResponse[]; } > => { - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const isLoggedIn = await getToken(request); if (!isLoggedIn.isLoggedIn) { diff --git a/app/routes/accounts.$id.edit.tsx b/app/routes/accounts.$id.edit.tsx index 6f216b4..afc2fb9 100644 --- a/app/routes/accounts.$id.edit.tsx +++ b/app/routes/accounts.$id.edit.tsx @@ -8,7 +8,7 @@ import { Form, redirect, useActionData, useLoaderData } from "react-router"; import { account, updateAccount } from "~/lib/api/account"; import { getToken } from "~/lib/api/getToken"; import { loggedInAccount } from "~/lib/api/loggedInAccount"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; const ERROR_MESSAGES = { invalidRequest: "Invalid request. Please try again.", @@ -45,9 +45,7 @@ export const loader = async ({ params, context, }: LoaderFunctionArgs): Promise => { - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const tokenData = await getToken(request); if (!tokenData.isLoggedIn) { @@ -87,9 +85,7 @@ export const action = async ({ params, context, }: ActionFunctionArgs): Promise => { - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const tokenData = await getToken(request); if (!tokenData.isLoggedIn) { diff --git a/app/routes/accounts.$id.follower.tsx b/app/routes/accounts.$id.follower.tsx index b212d99..18860b0 100644 --- a/app/routes/accounts.$id.follower.tsx +++ b/app/routes/accounts.$id.follower.tsx @@ -4,7 +4,7 @@ import { FollowAccount } from "~/components/followAccount"; import { account } from "~/lib/api/account"; import { getFollowersList, type FollowerResponse } from "~/lib/api/followlist"; import { getToken } from "~/lib/api/getToken"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; export async function loader({ params, @@ -13,9 +13,7 @@ export async function loader({ }: LoaderFunctionArgs): Promise< { isSuccess: false } | { isSuccess: true; response: FollowerResponse[] } > { - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const isLoggedIn = await getToken(request); if (!isLoggedIn.isLoggedIn) { diff --git a/app/routes/accounts.$id.following.tsx b/app/routes/accounts.$id.following.tsx index b276db2..ad12969 100644 --- a/app/routes/accounts.$id.following.tsx +++ b/app/routes/accounts.$id.following.tsx @@ -4,7 +4,7 @@ import { FollowAccount } from "~/components/followAccount"; import { account } from "~/lib/api/account"; import { getFollowingList, type FollowingResponse } from "~/lib/api/followlist"; import { getToken } from "~/lib/api/getToken"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; export async function loader({ params, @@ -13,9 +13,7 @@ export async function loader({ }: LoaderFunctionArgs): Promise< { isSuccess: false } | { isSuccess: true; response: FollowingResponse[] } > { - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const isLoggedIn = await getToken(request); if (!isLoggedIn.isLoggedIn) { diff --git a/app/routes/api.follow.ts b/app/routes/api.follow.ts index 7c578f6..6f9b5aa 100644 --- a/app/routes/api.follow.ts +++ b/app/routes/api.follow.ts @@ -4,7 +4,7 @@ import { redirect } from "react-router"; import { followAccount, unfollowAccount } from "~/lib/api/follow"; import { getToken } from "~/lib/api/getToken"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -19,9 +19,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { try { const formData = await request.formData(); - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; switch (request.method) { case "POST": { diff --git a/app/routes/api.notes.ts b/app/routes/api.notes.ts index 2d7a7ea..4d25f4f 100644 --- a/app/routes/api.notes.ts +++ b/app/routes/api.notes.ts @@ -5,7 +5,7 @@ import { redirect } from "react-router"; import { apiOptions, parseApiErrorMessage } from "~/lib/api/client"; import { getToken } from "~/lib/api/getToken"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -20,9 +20,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { try { const formData = await request.formData(); - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const { error } = await postV0Notes({ ...apiOptions(basePath, token), body: { diff --git a/app/routes/api.reaction.ts b/app/routes/api.reaction.ts index 2236eb9..30210f6 100644 --- a/app/routes/api.reaction.ts +++ b/app/routes/api.reaction.ts @@ -8,7 +8,7 @@ import { redirect } from "react-router"; import { apiOptions } from "~/lib/api/client"; import { getToken } from "~/lib/api/getToken"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -22,9 +22,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { const token = isLoggedIn.token; const formData = await request.formData(); - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; switch (request.method) { case "POST": diff --git a/app/routes/api.renote.ts b/app/routes/api.renote.ts index 098d2f7..3277b33 100644 --- a/app/routes/api.renote.ts +++ b/app/routes/api.renote.ts @@ -4,7 +4,7 @@ import { redirect } from "react-router"; import { getToken } from "~/lib/api/getToken"; import { renote } from "~/lib/api/renote"; import { checkOrigin, throwForbiddenResponse } from "~/lib/checkOrigin"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; export const action = async ({ request, context }: ActionFunctionArgs) => { if (!checkOrigin(request)) { @@ -24,9 +24,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { const formData = await request.formData(); const noteID = formData.get("noteID") as string; - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const result = await renote(basePath, token, noteID, { content: "", diff --git a/app/routes/login.tsx b/app/routes/login.tsx index 713f6c9..5032502 100644 --- a/app/routes/login.tsx +++ b/app/routes/login.tsx @@ -2,7 +2,7 @@ import type { ActionFunctionArgs, MetaFunction } from "react-router"; import { Form, Link, redirect, useActionData } from "react-router"; import { accountCookie, login } from "~/lib/api/login"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; import styles from "~/components/login.module.css"; @@ -31,9 +31,7 @@ export const action = async ({ request, context }: ActionFunctionArgs) => { const email = formData.get("email") as string; const passphrase = formData.get("passphrase") as string; - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const res = await login({ email, passphrase }, basePath); if ("error" in res) { const errorMessage = diff --git a/app/routes/signup._index.tsx b/app/routes/signup._index.tsx index 2dc46a6..bffcebc 100644 --- a/app/routes/signup._index.tsx +++ b/app/routes/signup._index.tsx @@ -4,7 +4,7 @@ import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router"; import { Form, Link, redirect, useLoaderData } from "react-router"; import { apiOptions } from "~/lib/api/client"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; import { logger } from "~/lib/logger"; import styles from "~/components/signup.module.css"; @@ -22,7 +22,7 @@ export const action = async ({ try { const env = context.get(cloudflareContext).env; const { error } = await postV0Accounts({ - ...apiOptions(getApiBasePath(env.API_BASE_URL)), + ...apiOptions(env.API_BASE_URL), body: { name: `@${name}@${env.INSTANCE_FQDN}`, email, diff --git a/app/routes/signup.verify.tsx b/app/routes/signup.verify.tsx index 475d2e4..efe6ea5 100644 --- a/app/routes/signup.verify.tsx +++ b/app/routes/signup.verify.tsx @@ -3,7 +3,7 @@ import type { LoaderFunctionArgs } from "react-router"; import { Link, useLoaderData } from "react-router"; import { apiOptions } from "~/lib/api/client"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; import { logger } from "~/lib/logger"; export const loader = async ({ @@ -24,9 +24,7 @@ export const loader = async ({ } try { - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; if (basePath == null) { logger.error("API_BASE_URL env was not configured"); return { error: "Something went wrong" }; diff --git a/app/routes/timeline.tsx b/app/routes/timeline.tsx index 5f4577d..aaf5057 100644 --- a/app/routes/timeline.tsx +++ b/app/routes/timeline.tsx @@ -10,7 +10,7 @@ import { accountCookie } from "~/lib/api/login"; import { fetchNote } from "~/lib/api/note"; import type { TimelineResponse, TimelineType } from "~/lib/api/timeline"; import { fetchTimeline } from "~/lib/api/timeline"; -import { cloudflareContext, getApiBasePath } from "~/lib/cloudflareContext"; +import { cloudflareContext } from "~/lib/cloudflareContext"; import styles from "~/styles/timeline.module.css"; @@ -30,9 +30,7 @@ export const loader = async ({ timeline: TimelineType; } > => { - const basePath = getApiBasePath( - context.get(cloudflareContext).env.API_BASE_URL - ); + const basePath = context.get(cloudflareContext).env.API_BASE_URL; const cookie = await accountCookie.parse(request.headers.get("Cookie")); if (!cookie) { diff --git a/wrangler.jsonc b/wrangler.jsonc index 9ba57ff..beb194d 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -3,56 +3,60 @@ * https://developers.cloudflare.com/workers/wrangler/configuration/ */ { - "$schema": "node_modules/wrangler/config-schema.json", - "name": "caramel", - "compatibility_date": "2025-04-04", - "main": "./workers/app.ts", - "observability": { - "enabled": true + "$schema": "node_modules/wrangler/config-schema.json", + "name": "caramel", + "compatibility_date": "2025-04-04", + "main": "./workers/app.ts", + "observability": { + "enabled": true, + }, + "vars": { + "API_BASE_URL": "http://localhost:3000", + "INSTANCE_FQDN": "example.com", + }, + "env": { + "demo": { + "vars": { + "API_BASE_URL": "https://demo.pulsate.dev", + "INSTANCE_FQDN": "demo.pulsate.dev", + }, }, - "env": { - "demo": { - "vars": { - "API_BASE_URL": "https://demo.pulsate.dev", - "INSTANCE_FQDN": "demo.pulsate.dev" - } - }, - "ci": { - "vars": { - "API_BASE_URL": "http://localhost:3000", - "INSTANCE_FQDN": "example.com", - "TURNSTILE_KEY": "1x00000000000000000000AA" - } - } - } - /** - * Smart Placement - * Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement - */ - // "placement": { "mode": "smart" }, - /** - * Bindings - * Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including - * databases, object storage, AI inference, real-time communication and more. - * https://developers.cloudflare.com/workers/runtime-apis/bindings/ - */ - /** - * Environment Variables - * https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables - */ - // "vars": { "MY_VARIABLE": "production_value" }, - /** - * Note: Use secrets to store sensitive data. - * https://developers.cloudflare.com/workers/configuration/secrets/ - */ - /** - * Static Assets - * https://developers.cloudflare.com/workers/static-assets/binding/ - */ - // "assets": { "directory": "./public/", "binding": "ASSETS" }, - /** - * Service Bindings (communicate between multiple Workers) - * https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings - */ - // "services": [{ "binding": "MY_SERVICE", "service": "my-service" }] + "ci": { + "vars": { + "API_BASE_URL": "http://localhost:3000", + "INSTANCE_FQDN": "example.com", + "TURNSTILE_KEY": "1x00000000000000000000AA", + }, + }, + }, + /** + * Smart Placement + * Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement + */ + // "placement": { "mode": "smart" }, + /** + * Bindings + * Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including + * databases, object storage, AI inference, real-time communication and more. + * https://developers.cloudflare.com/workers/runtime-apis/bindings/ + */ + /** + * Environment Variables + * https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables + */ + // "vars": { "MY_VARIABLE": "production_value" }, + /** + * Note: Use secrets to store sensitive data. + * https://developers.cloudflare.com/workers/configuration/secrets/ + */ + /** + * Static Assets + * https://developers.cloudflare.com/workers/static-assets/binding/ + */ + // "assets": { "directory": "./public/", "binding": "ASSETS" }, + /** + * Service Bindings (communicate between multiple Workers) + * https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings + */ + // "services": [{ "binding": "MY_SERVICE", "service": "my-service" }] }