Skip to content

Commit

Permalink
feat(api): add v1 prefix for request all endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Mar 13, 2024
1 parent 735815f commit 2d732b9
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docker-compose.mock.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
qualtet_mock:
image: ghcr.io/yoshinorin/docker-qualtet-mock:v2.11.0.0-rc3
image: ghcr.io/yoshinorin/docker-qualtet-mock:v2.12.0.0
expose:
- "9002"
ports:
Expand Down
3 changes: 2 additions & 1 deletion src/app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { api } from '../../../config';
// TODO: move somewhere if possible
const cachedFindByPath = cache(async (path: string) => {
const ctx = requestContextFrom(headers());
const slug = sluggize(['contents', path]);
// TODO: devide into another `function` and move `api` dir.
const slug = sluggize(['v1', 'contents', path]);
const url = buildUrl(api.url, slug, true);
const response = await fetchFromApi(url, null, ctx, {
interceptIfContainsIgnorePaths: true
Expand Down
3 changes: 2 additions & 1 deletion src/app/archives/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ async function run(req: any): Promise<any> {

async function handler(req: any) {
const ctx = requestContextFrom(headers());
const url = buildUrl(api.url, 'archives', true);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, 'v1/archives', true);
const response: Response = await fetchFromApi(url, null, ctx, null);
throwIfError(response);

Expand Down
3 changes: 2 additions & 1 deletion src/app/articles/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const PREFIX_URL = 'articles';
// TODO: move somewhere if possible
const cachedFindByPath = cache(async (path: string) => {
const ctx = requestContextFrom(headers());
const slug = sluggize(['contents', path]);
// TODO: devide into another `function` and move `api` dir.
const slug = sluggize(['v1', 'contents', path]);
const url = buildUrl(api.url, slug, true);
const response = await fetchFromApi(url, null, ctx, {
interceptIfContainsIgnorePaths: true
Expand Down
3 changes: 2 additions & 1 deletion src/app/articles/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ async function run(req: any): Promise<any> {
async function handler(req: any) {
const currentPage = req.searchParams['p'] ? req.searchParams['p'] : 1;
const ctx = requestContextFrom(headers());
const url = buildUrl(api.url, 'articles', true);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, 'v1/articles', true);
const queryParams = buildQueryParams(null, { page: currentPage, limit: 10 });
const response: Response = await fetchFromApi(url, queryParams, ctx, null);
throwIfError(response);
Expand Down
3 changes: 2 additions & 1 deletion src/app/feeds/index.xml/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { buildUrl, sluggize } from '../../../utils/url';
//export async function get(ctx: any) {
export async function GET() {
const ctx = requestContextFrom(headers());
const apiUrl = buildUrl(api.url, sluggize(['feeds', 'index']), false);
// TODO: devide into another `function` and move `api` dir.
const apiUrl = buildUrl(api.url, sluggize(['v1', 'feeds', 'index']), false);
const response: Response = await fetchFromApi(apiUrl, null, ctx, null);

if (response.status !== 200) {
Expand Down
3 changes: 2 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ async function run(req: any): Promise<any> {

async function handler(req: any) {
const ctx = requestContextFrom(headers());
const url = buildUrl(api.url, 'articles', true);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, 'v1/articles', true);
const queryParams = buildQueryParams(null, { page: 1, limit: 5 });
const response: Response = await fetchFromApi(url, queryParams, ctx, null);
throwIfError(response);
Expand Down
3 changes: 2 additions & 1 deletion src/app/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ async function handler(req: any) {

async function execute(req, words: Array<string>) {
const ctx = requestContextFrom(headers());
const url = buildUrl(api.url, sluggize(['search']), false);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, sluggize(['v1', 'search']), false);
const queryParams = buildQueryParams({ key: 'q', values: words })
const response = await fetchFromApi(url, queryParams, ctx, null);

Expand Down
7 changes: 4 additions & 3 deletions src/app/series/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { requestContextFrom } from '../../../utils/requestContext';
import { Renderer } from './renderer';
import { runWithHandleErrorIf, throwIfError } from "../../handler";
import { api } from '../../../../config';

const API_BASE_URL = `${api.url}/series`;
import { buildUrl, sluggize } from '../../../utils/url';

export default async function Page(req: any) {
return runWithHandleErrorIf(await run(req));
Expand All @@ -25,7 +24,9 @@ async function run(req: any): Promise<any> {
async function handler(req: any) {
const seriesName = req.params.slug;
const ctx = requestContextFrom(headers());
const response: Response = await fetchFromApi(`${API_BASE_URL}/${seriesName}`, ctx);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, sluggize(['v1', 'series', seriesName]), false);
const response: Response = await fetchFromApi(url, null, ctx);
throwIfError(response);

const seriresWithArticlesResponse: SeriresWithArticlesResponse = await response.json() as SeriresWithArticlesResponse;
Expand Down
3 changes: 2 additions & 1 deletion src/app/series/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ async function run(req: any): Promise<any> {

async function handler(req: any) {
const ctx = requestContextFrom(headers());
const url = buildUrl(api.url, sluggize(['series']), true);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, sluggize(['v1', 'series']), true);
const response: Response = await fetchFromApi(url, null, ctx, null);
throwIfError(response);

Expand Down
3 changes: 2 additions & 1 deletion src/app/sitemap.xml/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { buildUrl, sluggize } from '../../utils/url';

export async function GET() {
const ctx = requestContextFrom(headers());
const url = buildUrl(api.url, sluggize(['sitemaps']), true);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, sluggize(['v1', 'sitemaps']), true);
const response: Response = await fetchFromApi(url, null, ctx, null);

if (response.status !== 200) {
Expand Down
3 changes: 2 additions & 1 deletion src/app/status/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default async function Page(req: any) {

async function handler(req: any) {
const ctx = requestContextFrom(headers());
const url = buildUrl(api.url, sluggize(['system', 'health']), false);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, sluggize(['v1', 'system', 'health']), false);
const response: Response = await fetchFromApi(url, null, ctx, null);

return {
Expand Down
3 changes: 2 additions & 1 deletion src/app/tags/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ async function handler(req: any) {
const tagName = decodeURI(req.params.slug[0]);
const currentPage = req.searchParams['p'] ? req.searchParams['p'] : 1;
const ctx = requestContextFrom(headers());
const url = buildUrl(api.url, sluggize(['tags', encodeURI(tagName)]), false);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, sluggize(['v1', 'tags', encodeURI(tagName)]), false);
const queryParams = buildQueryParams(null, { page: currentPage, limit: 10 })
const response: Response = await fetchFromApi(url, queryParams, ctx, null);
throwIfError(response);
Expand Down
3 changes: 2 additions & 1 deletion src/app/tags/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ async function run(req: any): Promise<any> {

async function handler(req: any) {
const ctx = requestContextFrom(headers());
const url = buildUrl(api.url, sluggize(['tags']), true);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(api.url, sluggize(['v1', 'tags']), true);
const response: Response = await fetchFromApi(url, null, ctx, null);
throwIfError(response);

Expand Down
3 changes: 2 additions & 1 deletion src/components/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const ContentComponent: React.FunctionComponent<{ content: Content, insig
const [metaAndInsight, setData] = useState(null);

const fetchBackendMetaData = async () => {
const url = buildUrl(publicApi.url, sluggize(['system', 'metadata']), false);
// TODO: devide into another `function` and move `api` dir.
const url = buildUrl(publicApi.url, sluggize(['v1', 'system', 'metadata']), false);
const response: Response = await fetchFromApi(url, null, null, null);
let ins = insight;
if (response.status === 200) {
Expand Down

0 comments on commit 2d732b9

Please sign in to comment.