createApiUrl signature changed

This commit is contained in:
tmshv committed 2020-02-15 04:04:26 +03:00
1 parent b4da11e086
commit d3b5b2d5c6
12 files changed
+15 -18

No files matched your search

+1 -1
View File
@@ -32,7 +32,7 @@ const Page = (props) => (
Page.getInitialProps = wrapInitialProps(async (ctx) => {
const pageUrl = '/gallery'
const id = ctx.query.album
const album = await requestGet(createApiUrl(ctx.req, `/api/albums/${id}`), {})
const album = await requestGet(createApiUrl(`/api/albums/${id}`), {})
return {
album,
+1 -1
View File
@@ -37,7 +37,7 @@ const Page = (props) => (
Page.getInitialProps = wrapInitialProps(async (ctx) => {
const pageUrl = '/'
const id = ctx.query.article
const article = await requestGet(createApiUrl(ctx.req, `/api/articles/${id}`), {})
const article = await requestGet(createApiUrl(`/api/articles/${id}`), {})
const image = get(article, 'preview.artifacts.fb', {})
return {
+1 -1
View File
@@ -31,7 +31,7 @@ Page.getInitialProps = wrapInitialProps(async (ctx) => {
const pageUrl = '/'
const page = parseInt(ctx.query.page)
const pageSize = parseInt(ctx.query.pageSize) || 15
const res = await requestGet(createApiUrl(ctx.req, `/api/articles?page=${page}&pageSize=${pageSize}`), {})
const res = await requestGet(createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), {})
const articles = res.items || []
const nextPage = res.nextPage
const prevPage = res.prevPage
+2 -2
View File
@@ -63,11 +63,11 @@ const Page: NextPage<Props> = props => (
export const unstable_getServerProps = async (ctx: NextPageContext) => {
const pageUrl = ctx.req.url
const res = await requestGet<IResponseItems<IPerson>>(createApiUrl(ctx.req, '/api/persons'), { items: [] })
const res = await requestGet<IResponseItems<IPerson>>(createApiUrl('/api/persons'), { items: [] })
const persons = res.items || []
const title = 'Преподаватели Шлиссельбургской ДХШ'
const imageFile = 'Images/HudozkaCollective2017.jpg'
const resImage = await requestGet(createApiUrl(ctx.req, `/api/image?file=${imageFile}`), null)
const resImage = await requestGet(createApiUrl(`/api/image?file=${imageFile}`), null)
const image = get(resImage, 'artifacts.large', null)
return {
+1 -1
View File
@@ -28,7 +28,7 @@ const Page = (props) => (
Page.getInitialProps = wrapInitialProps(async (ctx) => {
const pageUrl = '/documents'
const id = ctx.query.document
const file = await requestGet(createApiUrl(ctx.req, `/api/files/${id}`), {})
const file = await requestGet(createApiUrl(`/api/files/${id}`), {})
return {
file,
+1 -1
View File
@@ -127,7 +127,7 @@ const Page: NextPage<IProps> = props => (
Page.getInitialProps = wrapInitialProps(async (ctx) => {
const pageUrl = '/documents'
const res = await requestGet<IResponseItems<IDocument>>(createApiUrl(ctx.req, '/api/files'), { items: [] })
const res = await requestGet<IResponseItems<IDocument>>(createApiUrl('/api/files'), { items: [] })
const files = res.items
const title = 'Документы'
const collections = getSorted(files)
+1 -1
View File
@@ -98,7 +98,7 @@ const Page: NextPage<IProps> = props => (
Page.getInitialProps = wrapInitialProps(async (ctx) => {
const pageUrl = ctx.req.url
const res = await requestGet<any>(createApiUrl(ctx.req, `/api/albums`), {})
const res = await requestGet<any>(createApiUrl(`/api/albums`), {})
const items = res.items || []
const albumCollections = albumsByYear(items)
const title = 'Галерея'
+1 -1
View File
@@ -45,7 +45,7 @@ Page.getInitialProps = wrapInitialProps(async (ctx) => {
const pageUrl = '/'
const page = 1
const pageSize = ctx.query.pageSize || 15
const res = await requestGet(createApiUrl(ctx.req, `/api/articles?page=${page}&pageSize=${pageSize}`), {}) as any
const res = await requestGet(createApiUrl(`/api/articles?page=${page}&pageSize=${pageSize}`), {}) as any
const articles = res.items || []
const nextPage = res.nextPage
const prevPage = res.prevPage
+1 -1
View File
@@ -31,7 +31,7 @@ const Index = props => (
Index.getInitialProps = wrapInitialProps(async (ctx) => {
const pageUrl = ctx.req.url
const page = await requestGet(createApiUrl(ctx.req, `/api/page?page=${pageUrl}`), {})
const page = await requestGet(createApiUrl(`/api/page?page=${pageUrl}`), {})
const image = page.preview ? page.preview.artifacts.fb : {}
return {
+1 -1
View File
@@ -30,7 +30,7 @@ Page.getInitialProps = wrapInitialProps(async (ctx) => {
const pageUrl = ctx.req.url
const period = '2016-2017'
const semester = 'spring'
const schedule = await requestGet(createApiUrl(ctx.req, `/api/schedule?period=${period}&semester=${semester}`), {})
const schedule = await requestGet(createApiUrl(`/api/schedule?period=${period}&semester=${semester}`), {})
return {
schedule,
+2 -3
View File
@@ -64,8 +64,7 @@ export const unstable_getStaticProps = async (ctx: any) => {
throw new Error('sry')
}
// const person: any = await requestGet(createApiUrl(ctx.req, `/api/persons/${id}`), {})
const person: any = await requestGet(`http://localhost:3000/api/persons/${id}`, {})
const person = await requestGet<any>(createApiUrl(`/api/persons/${id}`), null)
const name = person.name || []
const title = name.join(' ')
const image = person.preview ? person.preview.artifacts.fb : {}
@@ -92,7 +91,7 @@ export const unstable_getStaticProps = async (ctx: any) => {
export const unstable_getStaticPaths = async () => {
console.log('call unstable_getStaticPaths')
const urls = await requestGet<IResponseItems<string>>(`http://localhost:3000/api/persons/urls`, null)
const urls = await requestGet<IResponseItems<string>>(createApiUrl(`/api/persons/urls`), null)
// const urls = {items: ['/teacher/va-sarzhin']}
return {
+2 -4
View File
@@ -31,10 +31,8 @@ export function wrapInitialProps(fn: (ctx: NextPageContext) => void) {
}
}
export function createApiUrl(req, path) {
const { origin } = absoluteUrl(req, 'localhost:3000')
return `${origin}${path}`
export function createApiUrl(path: string) {
return `https://api.tmshv.com/hudozka${path}`
}
function absoluteUrl(req, defaultLocalhost) {