next pages uses absolute url resolver to access api from getInitialProps
This commit is contained in:
1 parent
28a4d05fe4
commit
a502ddd4df
14 files changed
+37
-24
No files matched your search
+2
-2
@@ -8,6 +8,7 @@ import { HudozkaTitle } from '../src/components/HudozkaTitle'
|
||||
import menuModel from '../src/models/menu'
|
||||
import { meta } from '../src/lib/meta'
|
||||
import { buildMenu } from '../src/lib/menu'
|
||||
import { createApiUrl } from '../src/next-lib'
|
||||
|
||||
const Page = (props) => (
|
||||
<App
|
||||
@@ -36,8 +37,7 @@ Page.getInitialProps = async (ctx) => {
|
||||
const pageUrl = '/'
|
||||
const page = 1
|
||||
const pageSize = ctx.query.pageSize || 15
|
||||
const apiUrl = `http://localhost:3000/api/articles?page=${page}&pageSize=${pageSize}`
|
||||
const res = await axios.get(apiUrl)
|
||||
const res = await axios.get(createApiUrl(ctx.req, `/api/articles?page=${page}&pageSize=${pageSize}`))
|
||||
const articles = res.data.items
|
||||
const nextPage = res.data.nextPage
|
||||
const prevPage = res.data.prevPage
|
||||
|
||||
Reference in new issue
Block a user