-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy path[...slug].tsx
More file actions
52 lines (43 loc) · 1.12 KB
/
[...slug].tsx
File metadata and controls
52 lines (43 loc) · 1.12 KB
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
import { Page } from '@customTypes/page'
import { Taxon } from '@customTypes/taxons'
import { ProductList } from '@components/product'
import { Layout } from '@components/common'
export const getServerSideProps = async ({ params }) => {
const baseUrl =
process.env.NODE_ENV === 'development'
? 'http://localhost:3000/api'
: '/api'
const { taxonomy, slug } = params
const pages: Page[] = await fetch(`${baseUrl}/pages`).then((res) =>
res.json()
)
const taxon: Taxon = await fetch(
`${baseUrl}/taxonomies/${taxonomy}/${slug}`
).then((res) => res.json())
const taxons: any = await fetch(`${baseUrl}/taxonomies`).then((res) =>
res.json()
)
const products: any = await fetch(
`${baseUrl}/products?taxons=${taxon.id}`
).then((res) => res.json())
return {
props: {
pages,
taxon,
taxons,
products,
},
}
}
const TaxonomyPage = ({ pages, taxon, taxons, products }) => {
return (
<ProductList
products={products}
pages={pages}
taxons={taxons}
taxon={taxon}
/>
)
}
export default TaxonomyPage
TaxonomyPage.Layout = Layout