Skip to content

Commit

Permalink
fix: Add weski proxy to fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
Najeong-Kim committed Aug 20, 2024
1 parent fb0a595 commit 8b4eb72
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
8 changes: 0 additions & 8 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ const nextConfig = {
images: {
domains: ['via.placeholder.com'],
},
async rewrites() {
return [
{
source: '/weski/api/:path*',
destination: process.env.NEXT_PUBLIC_API_URL + '/:path*',
},
];
},
};

export default nextConfig;
19 changes: 19 additions & 0 deletions src/pages/api/weski/[...path].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { API_URL } from '@/shared/config';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { path } = req.query;
const url = `${API_URL}/${(path as string[]).join('/')}`;

const response = await fetch(url, {
method: req.method,
headers: {
...(req.headers as Record<string, string>),
},
body: req.method !== 'GET' ? JSON.stringify(req.body) : undefined,
});

const data = await response.json();

res.status(response.status).json(data);
}
6 changes: 3 additions & 3 deletions src/shared/api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ApiClient {
endpoint: string,
queryParams?: Record<string, string | number>
): Promise<TResult> {
const url = new URL('/weski/api' + endpoint, this.baseUrl);
const url = new URL('/api/weski' + endpoint, window.location.origin);

if (queryParams) {
Object.entries(queryParams).forEach(([key, value]) => {
Expand All @@ -44,7 +44,7 @@ export class ApiClient {
endpoint: string,
body: TData
): Promise<TResult> {
const url = new URL('/weski/api' + endpoint, this.baseUrl);
const url = new URL('/api/weski' + endpoint, window.location.origin);

const response = await fetch(url.toString(), {
method: 'POST',
Expand All @@ -58,4 +58,4 @@ export class ApiClient {
}
}

export const apiClient = new ApiClient(window.location.origin);
export const apiClient = new ApiClient('');

0 comments on commit 8b4eb72

Please sign in to comment.