Commit cb603dd3 authored by tom's avatar tom

add prefix to proxy path

parent ec77fa3d
async function rewrites() { async function rewrites() {
return [ return [
{ source: '/node-api/proxy/:slug*', destination: '/api/proxy' },
{ source: '/node-api/:slug*', destination: '/api/:slug*' }, { source: '/node-api/:slug*', destination: '/api/:slug*' },
{ source: '/proxy/:slug*', destination: '/api/proxy' },
].filter(Boolean); ].filter(Boolean);
} }
......
...@@ -24,7 +24,7 @@ export default function buildUrl( ...@@ -24,7 +24,7 @@ export default function buildUrl(
const baseUrl = needProxy ? appConfig.baseUrl : (resource.endpoint || appConfig.api.endpoint); const baseUrl = needProxy ? appConfig.baseUrl : (resource.endpoint || appConfig.api.endpoint);
const basePath = resource.basePath !== undefined ? resource.basePath : appConfig.api.basePath; const basePath = resource.basePath !== undefined ? resource.basePath : appConfig.api.basePath;
const path = needProxy ? '/proxy' + basePath + resource.path : basePath + resource.path; const path = needProxy ? '/node-api/proxy' + basePath + resource.path : basePath + resource.path;
const url = new URL(compile(path)(pathParams), baseUrl); const url = new URL(compile(path)(pathParams), baseUrl);
queryParams && Object.entries(queryParams).forEach(([ key, value ]) => { queryParams && Object.entries(queryParams).forEach(([ key, value ]) => {
......
...@@ -11,7 +11,7 @@ const handler = async(_req: NextApiRequest, res: NextApiResponse) => { ...@@ -11,7 +11,7 @@ const handler = async(_req: NextApiRequest, res: NextApiResponse) => {
} }
const response = await fetchFactory(_req, _req.headers['x-endpoint']?.toString())( const response = await fetchFactory(_req, _req.headers['x-endpoint']?.toString())(
_req.url.replace(/^\/proxy/, ''), _req.url.replace(/^\/node-api\/proxy/, ''),
_pickBy(_pick(_req, [ 'body', 'method' ]), Boolean), _pickBy(_pick(_req, [ 'body', 'method' ]), Boolean),
); );
......
...@@ -5,5 +5,5 @@ import { RESOURCES } from 'lib/api/resources'; ...@@ -5,5 +5,5 @@ import { RESOURCES } from 'lib/api/resources';
export default function buildApiUrl(resourceName: ResourceName, pathParams?: Record<string, string>) { export default function buildApiUrl(resourceName: ResourceName, pathParams?: Record<string, string>) {
const resource = RESOURCES[resourceName]; const resource = RESOURCES[resourceName];
return compile('/proxy/poa/core' + resource.path)(pathParams); return compile('/node-api/proxy/poa/core' + resource.path)(pathParams);
} }
import { test, expect, devices } from '@playwright/experimental-ct-react'; import { test, expect, devices } from '@playwright/experimental-ct-react';
import React from 'react'; import React from 'react';
import { RESOURCES } from 'lib/api/resources';
import * as profileMock from 'mocks/user/profile'; import * as profileMock from 'mocks/user/profile';
import authFixture from 'playwright/fixtures/auth'; import authFixture from 'playwright/fixtures/auth';
import TestApp from 'playwright/TestApp'; import TestApp from 'playwright/TestApp';
import buildApiUrl from 'playwright/utils/buildApiUrl';
import ProfileMenuMobile from './ProfileMenuMobile'; import ProfileMenuMobile from './ProfileMenuMobile';
...@@ -30,7 +30,7 @@ test.describe('auth', () => { ...@@ -30,7 +30,7 @@ test.describe('auth', () => {
}); });
extendedTest('base view', async({ mount, page }) => { extendedTest('base view', async({ mount, page }) => {
await page.route('/proxy/poa/core' + RESOURCES.user_info.path, (route) => route.fulfill({ await page.route(buildApiUrl('user_info'), (route) => route.fulfill({
status: 200, status: 200,
body: JSON.stringify(profileMock.base), body: JSON.stringify(profileMock.base),
})); }));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment