Skip to content

Commit

Permalink
Change the domain of the backend API called by the frontend to an env…
Browse files Browse the repository at this point in the history
…ironment variable
  • Loading branch information
ryichk committed Jan 4, 2025
1 parent 45121c5 commit f343fe5
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion client/app/components/todo-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Input } from "./ui/input";
import { Textarea } from "./ui/textarea";
import { Dispatch, SetStateAction } from "react";
import { Todo } from "~/types";
import { API_DOMAIN } from "~/constants";

const formSchema = z.object({
title: z.string().min(2, {
Expand All @@ -34,7 +35,7 @@ export default function TodoForm({ accessToken, setTodos }: Props) {

const createTodo = async (values: z.infer<typeof formSchema>) => {
try {
const res = await fetch('http://localhost:8080/todos', {
const res = await fetch(`${API_DOMAIN}/todos`, {
method: 'POST',
headers: {
"Content-Type": "application/json",
Expand Down
2 changes: 0 additions & 2 deletions client/app/components/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use client"

import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { cva, type VariantProps } from "class-variance-authority"
Expand Down
1 change: 1 addition & 0 deletions client/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const COGNITO_USER_POOL_ID = import.meta.env.VITE_COGNITO_USER_POOL_ID;
export const COGNITO_CLIENT_ID = import.meta.env.VITE_COGNITO_CLIENT_ID;
export const COGNITO_REDIRECT_URI = import.meta.env.VITE_COGNITO_REDIRECT_URI;
export const COGNITO_DOMAIN = import.meta.env.VITE_COGNITO_DOMAIN;
export const API_DOMAIN= import.meta.env.VITE_API_DOMAIN;
2 changes: 0 additions & 2 deletions client/app/hooks/use-toast.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use client"

// Inspired by react-hot-toast library
import * as React from "react"

Expand Down
2 changes: 1 addition & 1 deletion client/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ export default function App() {
}

export function HydrateFallback() {
return <p>Loading...</p>;
return <p>ローディング中...</p>;
}
3 changes: 2 additions & 1 deletion client/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback, useEffect, useState } from "react";
import { useAuth } from "react-oidc-context";
import TodoForm from "~/components/todo-form";
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { API_DOMAIN } from "~/constants";
import { useToast } from "~/hooks/use-toast";
import { Todo } from "~/types";

Expand All @@ -21,7 +22,7 @@ export default function Index() {
const token = auth.user?.access_token ?? '';
const fetchTodos = useCallback(async () => {
try {
const res = await fetch('http://localhost:8080/todos', {
const res = await fetch(`${API_DOMAIN}/todos`, {
headers: {
Authorization: `Bearer ${token}`,
},
Expand Down

0 comments on commit f343fe5

Please sign in to comment.