Skip to content

Commit eaba254

Browse files
authored
docs(v1): prepare for cloudflare migration (#15395)
* docs(v1): prepare for cloudflare migration * fix app name * added build packages script * remove vercel files
1 parent b4f1f3d commit eaba254

25 files changed

Lines changed: 3490 additions & 893 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Index API Reference to Algolia
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
index:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-node@v4
12+
with:
13+
node-version: 18
14+
- name: Install dependencies
15+
run: yarn install --immutable
16+
working-directory: www
17+
- name: Run Algolia indexing
18+
run: node scripts/index-algolia.mjs
19+
working-directory: www/apps/api-reference
20+
env:
21+
NEXT_PUBLIC_ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
22+
ALGOLIA_WRITE_API_KEY: ${{ secrets.ALGOLIA_WRITE_API_KEY }}
23+
NEXT_PUBLIC_API_ALGOLIA_INDEX_NAME: ${{ secrets.API_ALGOLIA_INDEX_NAME }}
24+
NEXT_PUBLIC_SITE_URL: ${{ secrets.API_REFERENCE_URL }}
25+
NEXT_PUBLIC_BASE_PATH: /v1/api

www/apps/api-reference/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ specs/admin.oas.json
4040
specs/store.oas.json
4141

4242
# analyzer
43-
analyze
43+
analyze
44+
public/specs

www/apps/api-reference/app/algolia/route.ts

Lines changed: 0 additions & 152 deletions
This file was deleted.

www/apps/api-reference/app/assets/sitemap.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
import { MetadataRoute } from "next"
2-
import OpenAPIParser from "@readme/openapi-parser"
3-
import path from "path"
4-
import type { ExpandedDocument, Operation } from "../../types/openapi"
5-
import getUrl from "../../utils/get-url"
6-
import getSectionId from "../../utils/get-section-id"
7-
import getPathsOfTag from "../../utils/get-paths-of-tag"
8-
import { config } from "../../config"
92

103
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
114
return []
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { NextResponse } from "next/server"
2+
3+
export const runtime = "edge"
4+
5+
type RouteParams = { params: { area: string } }
6+
7+
export async function GET(request: Request, { params }: RouteParams) {
8+
const { searchParams, origin } = new URL(request.url)
9+
const { area } = params
10+
const expand = searchParams.get("expand")
11+
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""
12+
13+
if (area !== "admin" && area !== "store") {
14+
return NextResponse.json(
15+
{
16+
success: false,
17+
message: `area ${area} is not allowed`,
18+
},
19+
{
20+
status: 400,
21+
}
22+
)
23+
}
24+
25+
const baseSpecsRes = await fetch(
26+
`${origin}${basePath}/specs/${area}/base.json`
27+
)
28+
if (!baseSpecsRes.ok) {
29+
return NextResponse.json({ success: false }, { status: 500 })
30+
}
31+
32+
const baseSpecs = await baseSpecsRes.json()
33+
34+
if (expand) {
35+
const tagRes = await fetch(
36+
`${origin}${basePath}/specs/${area}/tags/${expand}.json`
37+
)
38+
if (tagRes.ok) {
39+
const paths = await tagRes.json()
40+
if (paths) {
41+
baseSpecs.expandedTags = {}
42+
baseSpecs.expandedTags[expand] = paths.paths
43+
}
44+
}
45+
}
46+
47+
return NextResponse.json(baseSpecs, {
48+
status: 200,
49+
})
50+
}

www/apps/api-reference/app/base-specs/route.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

www/apps/api-reference/app/download/[area]/route.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
import { existsSync, readFileSync } from "fs"
21
import { NextResponse } from "next/server"
3-
import path from "path"
2+
3+
export const runtime = "edge"
44

55
type DownloadParams = {
66
params: {
77
area: string
88
}
99
}
1010

11-
export function GET(request: Request, { params }: DownloadParams) {
11+
export async function GET(request: Request, { params }: DownloadParams) {
1212
const { area } = params
13-
const filePath = path.join(process.cwd(), "specs", area, "openapi.full.yaml")
13+
const { origin } = new URL(request.url)
14+
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""
1415

15-
if (!existsSync(filePath)) {
16+
const specRes = await fetch(
17+
`${origin}${basePath}/specs/${area}/openapi.full.yaml`
18+
)
19+
if (!specRes.ok) {
1620
return new NextResponse(null, {
1721
status: 404,
1822
})
1923
}
2024

21-
const fileContent = readFileSync(filePath)
22-
23-
return new Response(fileContent, {
25+
return new Response(specRes.body, {
2426
headers: {
2527
"Content-Type": "application/x-yaml",
2628
"Content-Disposition": `attachment; filename="openapi.yaml"`,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { NextResponse } from "next/server"
2+
3+
export const runtime = "edge"
4+
5+
type RouteParams = { params: { area: string } }
6+
7+
export async function GET(request: Request, { params }: RouteParams) {
8+
const { searchParams, origin } = new URL(request.url)
9+
const { area } = params
10+
const tagName = searchParams.get("tagName") || ""
11+
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""
12+
13+
if (area !== "admin" && area !== "store") {
14+
return NextResponse.json(
15+
{
16+
success: false,
17+
message: `area ${area} is not allowed`,
18+
},
19+
{
20+
status: 400,
21+
}
22+
)
23+
}
24+
25+
const tagRes = await fetch(
26+
`${origin}${basePath}/specs/${area}/tags/${tagName}.json`
27+
)
28+
if (!tagRes.ok) {
29+
return NextResponse.json(
30+
{ success: false, message: `tag ${tagName} not found` },
31+
{ status: 404 }
32+
)
33+
}
34+
35+
const paths = await tagRes.json()
36+
37+
return NextResponse.json(
38+
{
39+
paths: paths.paths,
40+
},
41+
{
42+
status: 200,
43+
}
44+
)
45+
}

0 commit comments

Comments
 (0)