Skip to content

Commit

Permalink
fix: [LINKER-84] dev:mock 실행 명령어 오류 해결 (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
useonglee authored Jan 18, 2024
1 parent 67ef6f0 commit a07f484
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 26 deletions.
3 changes: 1 addition & 2 deletions packages/ky/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import kyInstance, { createKyApis, prefix } from './kyInstance';
import kyInstance, { createKyApis } from './kyInstance';

export const ky = createKyApis(kyInstance);
export const API_URL = prefix;
22 changes: 4 additions & 18 deletions packages/ky/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,10 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"jsx": "preserve",
"outDir": "dist",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"baseUrl": ".",
"paths": {
"@*": ["./src/*"]
}
"preserveValueImports": false
},
"include": [
"next-env.d.ts",
"./src/**/*.tsx",
"./src/**/*.ts",
"./jest.config.ts",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
"include": ["./**/*.ts"]
}
1 change: 0 additions & 1 deletion services/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"dev": "next dev",
"mock": "ts-node ./src/__server__/http.ts",
"dev:mock": "concurrently --kill-others \"yarn dev\" \"yarn mock\"",

"build": "next build",
"start": "next start",
"lint": "next lint",
Expand Down
1 change: 1 addition & 0 deletions services/web/src/__server__/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const MOCK_API_URL = 'http://localhost:8000';
5 changes: 3 additions & 2 deletions services/web/src/__server__/mockApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { API_URL } from '@linker/ky';
import { DefaultBodyType, http, HttpResponse, PathParams, ResponseResolver } from 'msw';
import { HttpRequestResolverExtras } from 'msw/lib/core/handlers/HttpHandler';

import { MOCK_API_URL } from './constants';

type Resolver = ResponseResolver<HttpRequestResolverExtras<PathParams>> | DefaultBodyType;

type MockApi = Record<keyof typeof http, (endpoint: string, resolver: Resolver) => HttpResponse>;
Expand All @@ -15,7 +16,7 @@ export const mockApi: MockApi = new Proxy({} as MockApi, {
}

return (endpoint: string, resolver: Resolver) => {
const url = `${API_URL}${endpoint}`;
const url = `${MOCK_API_URL}${endpoint}`;

return http[key as keyof typeof http](url, (info) => {
if (typeof resolver !== 'function') {
Expand Down
7 changes: 4 additions & 3 deletions services/web/src/__server__/mocks/feed.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable max-len */
import { API_URL } from '@linker/ky';
import { http, HttpResponse } from 'msw';

import { MOCK_API_URL } from '../constants';

export const feedHandlers = [
http.get(`${API_URL}/v1/my`, () => {
http.get(`${MOCK_API_URL}/v1/my`, () => {
return HttpResponse.json({ data: my }, { status: 200 });
}),

http.get(`${API_URL}/v1/schedules/upcoming/recommendation`, () => {
http.get(`${MOCK_API_URL}/v1/schedules/upcoming/recommendation`, () => {
return HttpResponse.json({ data: upcomingSchedules }, { status: 200 });
}),
];
Expand Down

0 comments on commit a07f484

Please sign in to comment.