next pages uses absolute url resolver to access api from getInitialProps

This commit is contained in:
tmshv committed 2019-10-11 23:14:01 +03:00
1 parent 28a4d05fe4
commit a502ddd4df
14 files changed
+37 -24

No files matched your search

+4 -4
View File
@@ -9,6 +9,7 @@ import { CardList } from '../src/components/CardList'
import menuModel from '../src/models/menu'
import { buildMenu } from '../src/lib/menu'
import { meta } from '../src/lib/meta'
import { createApiUrl } from '../src/next-lib'
const Page = (props) => (
<App
@@ -49,13 +50,12 @@ const Page = (props) => (
Page.getInitialProps = async (ctx) => {
const pageUrl = ctx.req.url
const apiUrl = `http://localhost:3000/api/persons`
const res = await axios.get(apiUrl)
const res = await axios.get(createApiUrl(ctx.req, '/api/persons'))
const persons = res.data.items
const title = 'Преподаватели Шлиссельбургской ДХШ'
const imageFile = 'Images/HudozkaCollective2017.jpg'
const imageUrl = `http://localhost:3000/api/image?file=${imageFile}`
const resImage = await axios.get(imageUrl)
const resImage = await axios.get(createApiUrl(ctx.req, `/api/image?file=${imageFile}`))
return {
persons,