diff --git a/apps/backend/src/node.ts b/apps/backend/src/node.ts index e09d960..924a0d7 100644 --- a/apps/backend/src/node.ts +++ b/apps/backend/src/node.ts @@ -1,7 +1,7 @@ import { serve } from '@hono/node-server' -import { app } from './shared.ts' import { openAPISpecs } from 'hono-openapi' import { Scalar } from '@scalar/hono-api-reference' +import { app } from './shared.ts' import { openAPIOptions } from './constants/open-api.ts' app.get('/openapi', openAPISpecs(app, openAPIOptions)) @@ -13,4 +13,12 @@ app.get( url: '/openapi', }), ) -serve(app) + +const PORT = 3000 + +serve({ + fetch: app.fetch, + port: PORT, +}) + +console.log(`Server running at http://localhost:${PORT}`) diff --git a/apps/backend/src/shared.ts b/apps/backend/src/shared.ts index 6b8b5d9..f092d62 100644 --- a/apps/backend/src/shared.ts +++ b/apps/backend/src/shared.ts @@ -1,6 +1,11 @@ import { Hono } from 'hono' import { personHobbiesApp } from './routes/person__[person_id]__hobbies/person__[person_id]__hobbies.app.ts' +import { cors } from 'hono/cors' -const app = new Hono().route('/:person_id/hobbies', personHobbiesApp) +const app = new Hono() + +app.use('*', cors()) + +app.route('/:person_id/hobbies', personHobbiesApp) export { app } diff --git a/apps/frontend/src/hooks/useNetworkingParams.ts b/apps/frontend/src/hooks/useNetworkingParams.ts index 7c0e2de..3d69313 100644 --- a/apps/frontend/src/hooks/useNetworkingParams.ts +++ b/apps/frontend/src/hooks/useNetworkingParams.ts @@ -2,7 +2,7 @@ import { useMemo } from 'react' const getBaseUrl = (_env: ImportMetaEnv) => { // You can return different base URLs depending on your environmental vars - return `https://example.com` + return `http://localhost:3000` } export const useNetworkingParams = () => { diff --git a/apps/frontend/src/main.tsx b/apps/frontend/src/main.tsx index 35f28f1..6b9502d 100644 --- a/apps/frontend/src/main.tsx +++ b/apps/frontend/src/main.tsx @@ -4,6 +4,7 @@ import { App } from './App.tsx' async function enableMocking() { // You can add a check here for `dev` mode to conditionally enable this + if (!import.meta.env.VITEST) return const { worker } = await import('./utils/testing-utils/server') return worker.start() diff --git a/apps/frontend/src/services/people.ts b/apps/frontend/src/services/people.ts index 0abb406..f7fe3f6 100644 --- a/apps/frontend/src/services/people.ts +++ b/apps/frontend/src/services/people.ts @@ -40,7 +40,7 @@ const client = createClient() function getBaseFetchOptions({ baseUrl, body, signal }: BaseNetworkProp) { return { baseUrl, - body: JSON.stringify(body), + body, headers: { Accept: 'application/json', 'Content-Type': 'application/json', @@ -73,7 +73,7 @@ export async function createPersonHobbies({ person_id, }, }, - ...getBaseFetchOptions({ baseUrl, signal, body: new_hobbies }), + ...getBaseFetchOptions({ baseUrl, signal, body: { new_hobbies } }), ...props, }) diff --git a/apps/frontend/src/utils/testing-utils/people-mocks.ts b/apps/frontend/src/utils/testing-utils/people-mocks.ts index ea99525..ecaee02 100644 --- a/apps/frontend/src/utils/testing-utils/people-mocks.ts +++ b/apps/frontend/src/utils/testing-utils/people-mocks.ts @@ -2,7 +2,7 @@ import type { paths } from '../../services/schemas/people' import { createOpenApiHttp } from 'openapi-msw' // Should be replaced with an env var of some kind -const baseUrl = 'https://example.com' +const baseUrl = 'http://localhost:3000' export const http = createOpenApiHttp({ baseUrl,