Skip to content

Commit

Permalink
refactor(Api): move internal routes to /api/internal
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsKoud committed Oct 16, 2023
1 parent 455cb54 commit 5535093
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 7 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/web/src/app/bins/[id]/auth/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const AuthForm: React.FC<AuthFormProps> = ({ id }) => {

async function onSubmit(data: z.infer<typeof FormSchema>) {
try {
await axios.post(`/api/v1/bins/${id}`, data, { withCredentials: true });
await axios.post(`/api/internal/bins/${id}`, data, { withCredentials: true });
router.push(`/bins/${id}`);
} catch (err) {
const error = "isAxiosError" in err ? (err as AxiosError<{ message: string }>).response?.data.message || "n/a" : "n/a";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/bins/[id]/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function generateMetadata({ params }: { params: Record<string, string> })

const Page: React.FC<PageProps<Params<"id">>> = async ({ params }) => {
const host = headers().get("host")!;
const status = await axios.get(`${getProtocol()}${host}/api/v1/bins/${params.id}`, { headers: { Cookie: cookies().toString() } });
const status = await axios.get(`${getProtocol()}${host}/api/internal/bins/${params.id}`, { headers: { Cookie: cookies().toString() } });
if (typeof status.data === "object") redirect(`/bins/${params.id}`);

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/bins/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function generateMetadata({ params }: { params: Record<string, string> })

const Page: React.FC<PageProps<Params<"id">>> = async ({ params }) => {
const host = headers().get("host")!;
const bin = await axios.get(`${getProtocol()}${host}/api/v1/bins/${params.id}`, { headers: { Cookie: cookies().toString() } });
const bin = await axios.get(`${getProtocol()}${host}/api/internal/bins/${params.id}`, { headers: { Cookie: cookies().toString() } });
if (typeof bin.data !== "object") redirect(`/bins/${params.id}/auth`);

return <PasteBin id={params.id} {...bin.data} />;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/files/[id]/auth/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const AuthForm: React.FC<AuthFormProps> = ({ id }) => {

async function onSubmit(data: z.infer<typeof FormSchema>) {
try {
await axios.post(`/api/v1/files/${id}`, data, { withCredentials: true });
await axios.post(`/api/internal/files/${id}`, data, { withCredentials: true });
router.push(`/files/${id}`);
} catch (err) {
const error = "isAxiosError" in err ? (err as AxiosError<{ message: string }>).response?.data.message || "n/a" : "n/a";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/files/[id]/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function generateMetadata({ params }: { params: Record<string, string> })

const Page: React.FC<PageProps<Params<"id">>> = async ({ params }) => {
const host = headers().get("host")!;
const status = await axios.get(`${getProtocol()}${host}/api/v1/files/${params.id}`);
const status = await axios.get(`${getProtocol()}${host}/api/internal/files/${params.id}`);
if (typeof status.data === "object") redirect(`/files/${params.id}`);

return (
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/app/files/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import FileView from "./FileView";

export async function generateMetadata({ params }: { params: Record<string, string> }): Promise<Metadata> {
const host = headers().get("host")!;
const { data: file } = await axios.get<FileResponse>(`${getProtocol()}${host}/api/v1/files/${params.id}`, {
const { data: file } = await axios.get<FileResponse>(`${getProtocol()}${host}/api/internal/files/${params.id}`, {
headers: { Cookie: cookies().toString() }
});

Expand Down Expand Up @@ -50,7 +50,7 @@ export interface FileResponse {

const Page: React.FC<PageProps<Params<"id">>> = async ({ params }) => {
const host = headers().get("host")!;
const { data: file } = await axios.get<FileResponse>(`${getProtocol()}${host}/api/v1/files/${params.id}`, {
const { data: file } = await axios.get<FileResponse>(`${getProtocol()}${host}/api/internal/files/${params.id}`, {
headers: { Cookie: cookies().toString() }
});
if (typeof file !== "object") redirect(`/files/${params.id}/auth`);
Expand Down

0 comments on commit 5535093

Please sign in to comment.