-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnext.config.ts
63 lines (58 loc) · 1.37 KB
/
next.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { NextConfig } from 'next'
const nextConfig: NextConfig = {
// basePath: '/docs',
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'basehub.earth',
},
{
protocol: 'https',
hostname: 'assets.basehub.com',
},
],
},
async rewrites() {
const res = await fetch('https://api.basehub.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-basehub-token': process.env.BASEHUB_TOKEN!,
},
body: JSON.stringify({
query: `
query {
pages(first: 1) {
items {
_slug
articles {
items {
_slug
}
}
}
}
}
`,
}),
})
if (!res.ok) throw new Error('Failed to fetch rewrites')
const { data } = (await res.json()) as {
data: {
pages: {
items: { _slug: string; articles: { items: { _slug: string }[] } }[]
}
}
}
const firstPage = data.pages.items[0]
if (!firstPage) return []
return firstPage.articles.items.map((article) => {
return {
source: `/${article._slug}/:path*`,
destination: `/${firstPage._slug}/${article._slug}/:path*`,
}
})
},
}
export default nextConfig