From d3b5b2d5c6351eb7b83c3c812f43ed200fa7a4b1 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Sat, 15 Feb 2020 04:04:26 +0300 Subject: [PATCH] createApiUrl signature changed --- pages/album/[album].jsx | 2 +- pages/article/[article].jsx | 2 +- pages/articles/[page].jsx | 2 +- pages/collective.tsx | 4 ++-- pages/document/[document].jsx | 2 +- pages/documents.tsx | 2 +- pages/gallery.tsx | 2 +- pages/index.tsx | 2 +- pages/next.jsx | 2 +- pages/schedule.jsx | 2 +- pages/teacher/[person].tsx | 5 ++--- src/next-lib.ts | 6 ++---- 12 files changed, 15 insertions(+), 18 deletions(-) diff --git a/pages/album/[album].jsx b/pages/album/[album].jsx index b6199f7e..f61c4797 100644 --- a/pages/album/[album].jsx +++ b/pages/album/[album].jsx @@ -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, diff --git a/pages/article/[article].jsx b/pages/article/[article].jsx index 84a92733..dfe5398d 100644 --- a/pages/article/[article].jsx +++ b/pages/article/[article].jsx @@ -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 { diff --git a/pages/articles/[page].jsx b/pages/articles/[page].jsx index 744da190..2b0cb43f 100644 --- a/pages/articles/[page].jsx +++ b/pages/articles/[page].jsx @@ -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 diff --git a/pages/collective.tsx b/pages/collective.tsx index 335b73e5..dcfa4354 100644 --- a/pages/collective.tsx +++ b/pages/collective.tsx @@ -63,11 +63,11 @@ const Page: NextPage = props => ( export const unstable_getServerProps = async (ctx: NextPageContext) => { const pageUrl = ctx.req.url - const res = await requestGet>(createApiUrl(ctx.req, '/api/persons'), { items: [] }) + const res = await requestGet>(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 { diff --git a/pages/document/[document].jsx b/pages/document/[document].jsx index 47bb7748..31510772 100644 --- a/pages/document/[document].jsx +++ b/pages/document/[document].jsx @@ -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, diff --git a/pages/documents.tsx b/pages/documents.tsx index e7276c37..0074f462 100644 --- a/pages/documents.tsx +++ b/pages/documents.tsx @@ -127,7 +127,7 @@ const Page: NextPage = props => ( Page.getInitialProps = wrapInitialProps(async (ctx) => { const pageUrl = '/documents' - const res = await requestGet>(createApiUrl(ctx.req, '/api/files'), { items: [] }) + const res = await requestGet>(createApiUrl('/api/files'), { items: [] }) const files = res.items const title = 'Документы' const collections = getSorted(files) diff --git a/pages/gallery.tsx b/pages/gallery.tsx index 83efd772..5ccfc13a 100644 --- a/pages/gallery.tsx +++ b/pages/gallery.tsx @@ -98,7 +98,7 @@ const Page: NextPage = props => ( Page.getInitialProps = wrapInitialProps(async (ctx) => { const pageUrl = ctx.req.url - const res = await requestGet(createApiUrl(ctx.req, `/api/albums`), {}) + const res = await requestGet(createApiUrl(`/api/albums`), {}) const items = res.items || [] const albumCollections = albumsByYear(items) const title = 'Галерея' diff --git a/pages/index.tsx b/pages/index.tsx index d3265270..670a1156 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -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 diff --git a/pages/next.jsx b/pages/next.jsx index abbd9630..bb520756 100644 --- a/pages/next.jsx +++ b/pages/next.jsx @@ -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 { diff --git a/pages/schedule.jsx b/pages/schedule.jsx index a26929cc..d2028fac 100644 --- a/pages/schedule.jsx +++ b/pages/schedule.jsx @@ -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, diff --git a/pages/teacher/[person].tsx b/pages/teacher/[person].tsx index b2316f88..cdedc89d 100644 --- a/pages/teacher/[person].tsx +++ b/pages/teacher/[person].tsx @@ -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(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>(`http://localhost:3000/api/persons/urls`, null) + const urls = await requestGet>(createApiUrl(`/api/persons/urls`), null) // const urls = {items: ['/teacher/va-sarzhin']} return { diff --git a/src/next-lib.ts b/src/next-lib.ts index e6ee490c..7210d5a7 100644 --- a/src/next-lib.ts +++ b/src/next-lib.ts @@ -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) {