File tree Expand file tree Collapse file tree 4 files changed +263
-293
lines changed
Expand file tree Collapse file tree 4 files changed +263
-293
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,9 @@ export default function HomePage() {
3131 let errorMessage = "イベントの取得に失敗しました。" ;
3232 try {
3333 const data = await res . json ( ) ;
34- if ( data && typeof data . message === "string" && data . message . trim ( ) ) {
35- errorMessage = data . message . trim ( ) ;
34+ const err = data as unknown as { message : string } ; // Middleware のレスポンスは Hono RPC の型に乗らない
35+ if ( typeof err . message === "string" && err . message . trim ( ) ) {
36+ errorMessage = err . message . trim ( ) ;
3637 }
3738 } catch ( _ ) {
3839 // レスポンスがJSONでない場合は無視
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ export default function ProjectPage() {
9393 projectName : string ;
9494 } | null > ( null ) ;
9595
96+ // TODO: グローバルにしないと、delete の際は遷移を伴うので表示されない
9697 const [ toast , setToast ] = useState < {
9798 message : string ;
9899 variant : "success" | "error" ;
@@ -215,9 +216,8 @@ export default function ProjectPage() {
215216 projectName : name ,
216217 } ) ;
217218 } else {
218- const { message } = await res . json ( ) ;
219219 setToast ( {
220- message,
220+ message : "イベントの作成に失敗しました。" ,
221221 variant : "error" ,
222222 } ) ;
223223 setTimeout ( ( ) => setToast ( null ) , 3000 ) ;
@@ -604,6 +604,7 @@ export default function ProjectPage() {
604604 if ( ! res . ok ) {
605605 throw new Error ( "削除に失敗しました。" ) ;
606606 }
607+ // TODO: トーストをグローバルにする
607608 navigate ( "/home" ) ;
608609 setToast ( {
609610 message : "イベントを削除しました。" ,
Original file line number Diff line number Diff line change @@ -3,16 +3,23 @@ import { PrismaClient } from "@prisma/client";
33import dotenv from "dotenv" ;
44import { Hono } from "hono" ;
55import { cors } from "hono/cors" ;
6+ import { customAlphabet } from "nanoid" ;
67import { browserIdMiddleware } from "./middleware/browserId.js" ;
78import projectsRoutes from "./routes/projects.js" ;
89
910dotenv . config ( ) ;
1011
12+ /**
13+ * ハイフン・アンダースコアを含まない Nano ID 形式。
14+ */
15+ export const nanoid = customAlphabet ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" , 21 ) ;
16+
1117export const prisma = new PrismaClient ( ) ;
12- const port = process . env . PORT || 3000 ;
18+
19+ const port = Number ( process . env . PORT ) || 3000 ;
1320const allowedOrigins = process . env . CORS_ALLOW_ORIGINS ?. split ( "," ) || [ ] ;
1421
15- type AppVariables = {
22+ export type AppVariables = {
1623 browserId : string ;
1724} ;
1825
@@ -28,12 +35,16 @@ const app = new Hono<{ Variables: AppVariables }>()
2835 . get ( "/" , ( c ) => {
2936 return c . json ( { message : "Hello! イツヒマ?" } ) ;
3037 } )
31- . route ( "/projects" , projectsRoutes ) ;
38+ . route ( "/projects" , projectsRoutes )
39+ . onError ( ( err , c ) => {
40+ console . error ( err ) ;
41+ return c . json ( { message : "Internal Server Error" } , 500 ) ;
42+ } ) ;
3243
3344serve (
3445 {
3546 fetch : app . fetch ,
36- port : Number ( port ) ,
47+ port,
3748 hostname : "0.0.0.0" ,
3849 } ,
3950 ( ) => {
You can’t perform that action at this time.
0 commit comments