getInitialProps request stability improvements
This commit is contained in:
1 parent
95c8369df2
commit
7ab68f5a8e
13 files changed
+65
-55
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import React from 'react'
|
||||
import axios from 'axios'
|
||||
import Head from 'next/head'
|
||||
import { App } from '../src/components/App'
|
||||
import { Meta } from '../src/components/Meta'
|
||||
@@ -9,7 +8,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'
|
||||
import { createApiUrl, requestGet } from '../src/next-lib'
|
||||
|
||||
const Page = (props) => (
|
||||
<App
|
||||
@@ -51,15 +50,16 @@ const Page = (props) => (
|
||||
Page.getInitialProps = async (ctx) => {
|
||||
const pageUrl = ctx.req.url
|
||||
|
||||
const res = await axios.get(createApiUrl(ctx.req, '/api/persons'))
|
||||
const persons = res.data.items
|
||||
const res = await requestGet(createApiUrl(ctx.req, '/api/persons'), {})
|
||||
const persons = res.items || []
|
||||
const title = 'Преподаватели Шлиссельбургской ДХШ'
|
||||
const imageFile = 'Images/HudozkaCollective2017.jpg'
|
||||
const resImage = await axios.get(createApiUrl(ctx.req, `/api/image?file=${imageFile}`))
|
||||
const resImage = await requestGet(createApiUrl(ctx.req, `/api/image?file=${imageFile}`), null)
|
||||
const image = resImage ? resImage.data.artifacts.large : null
|
||||
|
||||
return {
|
||||
persons,
|
||||
image: resImage.data.artifacts.large,
|
||||
image,
|
||||
pageUrl,
|
||||
title,
|
||||
meta: meta({
|
||||
|
||||
Reference in new issue
Block a user