@newskit-render/core 1.79.1 → 1.79.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.79.1](https://github.com/newscorp-ghfb/ncu-newskit-render/compare/@newskit-render/core@1.79.1-alpha.0...@newskit-render/core@1.79.1) (2022-08-01)
7
+
8
+ **Note:** Version bump only for package @newskit-render/core
9
+
10
+
11
+
12
+
13
+
6
14
  # [1.79.0](https://github.com/newscorp-ghfb/ncu-newskit-render/compare/@newskit-render/core@1.79.0-alpha.0...@newskit-render/core@1.79.0) (2022-07-28)
7
15
 
8
16
  **Note:** Version bump only for package @newskit-render/core
package/README.md CHANGED
@@ -27,7 +27,6 @@ npm start
27
27
  In order to run the application,we need the following required environment variables.
28
28
 
29
29
  ```
30
- SITE_HOST=""
31
30
  NEWSKIT_API_ENV_URL=""
32
31
  NEWSKIT_API_X_API_KEY=""
33
32
  OKTA_CLIENT_ID=""
@@ -54,9 +54,9 @@ const props: ArticleSlug = {
54
54
  ],
55
55
  },
56
56
  },
57
- articleURL: 'hostname/section/test-1/slugche' as URL,
57
+ articleURL: 'https://hostname/section/test-1/slugche' as URL,
58
58
  twitterUsername: 'D_Trump',
59
- siteHost: 'hostname',
59
+ siteHost: 'https://hostname',
60
60
  gscId: '4320982',
61
61
  articleId: 'test-1',
62
62
  }
@@ -69,7 +69,7 @@ const user = {
69
69
  subscriptions: [{ endDate: null }],
70
70
  }
71
71
  jest.mock('swr')
72
- const swrMock = useSWR as jest.Mock
72
+ let swrMock
73
73
 
74
74
  jest.mock('next/router', () => {
75
75
  return {
@@ -78,7 +78,6 @@ jest.mock('next/router', () => {
78
78
  })
79
79
 
80
80
  jest.mock('../../config', () => ({
81
- siteHost: 'hostname',
82
81
  twitterUsername: 'D_Trump',
83
82
  gscId: '4320982',
84
83
  }))
@@ -131,7 +130,7 @@ describe('Article', () => {
131
130
  section: 'section',
132
131
  articleSlug: 'slugche',
133
132
  },
134
- req: { headers: { cookie: 'some-cookie' } },
133
+ req: { headers: { cookie: 'some-cookie', host: 'hostname' } },
135
134
  res: { setHeader: setHeaderMock },
136
135
  })
137
136
  expect(response).toEqual({ props: { ...props, showAds: true, user } })
@@ -144,6 +143,9 @@ describe('Article', () => {
144
143
  })
145
144
 
146
145
  describe('Recommendation', () => {
146
+ beforeEach(() => {
147
+ swrMock = useSWR as jest.Mock
148
+ })
147
149
  afterEach(() => {
148
150
  jest.clearAllMocks()
149
151
  })
@@ -5,7 +5,6 @@ import RelatedArticlesPage, {
5
5
  getServerSideProps,
6
6
  } from '../../pages/[section]/[articleId]/relatedArticles'
7
7
  import { renderWithTheme } from '../../helpers/test-utils'
8
- import { recomendationsMock } from '../../helpers/mocks/getRecommendationsMock'
9
8
 
10
9
  const props: RelatedArticles = {
11
10
  articleId: 'test-1',
@@ -19,7 +18,7 @@ const user = {
19
18
  subscriptions: [{ endDate: null }],
20
19
  }
21
20
  jest.mock('swr')
22
- const swrMock = useSWR as jest.Mock
21
+ let swrMock
23
22
 
24
23
  jest.mock('newrelic', () => {
25
24
  return {
@@ -47,7 +46,6 @@ describe('Article', () => {
47
46
  describe('getServerSideProps', () => {
48
47
  beforeAll(() => {
49
48
  process.env = Object.assign(process.env, {
50
- SITE_HOST: 'hostname',
51
49
  TWITTER_USERNAME: 'D_Trump',
52
50
  GSC_ID: '4320982',
53
51
  })
@@ -73,6 +71,9 @@ describe('Article', () => {
73
71
  })
74
72
 
75
73
  describe('Recommendation', () => {
74
+ beforeEach(() => {
75
+ swrMock = useSWR as jest.Mock
76
+ })
76
77
  afterEach(() => {
77
78
  jest.clearAllMocks()
78
79
  })
@@ -87,7 +88,18 @@ describe('Recommendation', () => {
87
88
  it('render related article page', async () => {
88
89
  let result
89
90
  await act(async () => {
90
- swrMock.mockReturnValueOnce({ data: recomendationsMock })
91
+ swrMock.mockReturnValueOnce({
92
+ data: [
93
+ {
94
+ href:
95
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/image-656eaa885d.jpg?strip=all&w=600&h=338&crop=1',
96
+ tag: 'FOOT ON THE GAZ',
97
+ text:
98
+ 'Bale considering short deal with new club before RETIRING after World Cup',
99
+ title: 'FOOT ON THE GAZ',
100
+ },
101
+ ],
102
+ })
91
103
  result = renderWithTheme(RelatedArticlesPage)
92
104
  })
93
105
  expect(result.findByTestId('articleRec-1')).toBeDefined()
@@ -1060,7 +1060,7 @@ exports[`Article should render tile and sub title 1`] = `
1060
1060
  >
1061
1061
  <a
1062
1062
  class="nk-card-link css-1cq1vxv"
1063
- href="https://newskit-render.ceng-dev.newsuk.tech"
1063
+ href="http://localhost"
1064
1064
  >
1065
1065
  <section
1066
1066
  class="css-1mwgn7o"
@@ -1112,7 +1112,7 @@ exports[`Article should render tile and sub title 1`] = `
1112
1112
  >
1113
1113
  <a
1114
1114
  class="nk-card-link css-1cq1vxv"
1115
- href="https://newskit-render.ceng-dev.newsuk.tech"
1115
+ href="http://localhost"
1116
1116
  >
1117
1117
  <section
1118
1118
  class="css-1mwgn7o"
@@ -1312,7 +1312,7 @@ exports[`Article should render tile and sub title 1`] = `
1312
1312
  >
1313
1313
  <a
1314
1314
  class="nk-card-link css-1cq1vxv"
1315
- href="https://newskit-render.ceng-dev.newsuk.tech"
1315
+ href="http://localhost"
1316
1316
  >
1317
1317
  <section
1318
1318
  class="css-zs57uu"
@@ -1376,7 +1376,7 @@ exports[`Article should render tile and sub title 1`] = `
1376
1376
  >
1377
1377
  <a
1378
1378
  class="nk-card-link css-1cq1vxv"
1379
- href="https://newskit-render.ceng-dev.newsuk.tech"
1379
+ href="http://localhost"
1380
1380
  >
1381
1381
  <section
1382
1382
  class="css-zs57uu"
@@ -74,13 +74,11 @@ const articleData: ArticleProps = {
74
74
  relatedArticles: [
75
75
  {
76
76
  title: 'Prince Harry',
77
- tag: 'NEWS',
78
77
  text: 'news',
79
78
  href: 'https://plchldr.co/i/70x50',
80
79
  },
81
80
  {
82
81
  title: 'Meghan Markle',
83
- tag: 'SPORT',
84
82
  text: 'news',
85
83
  href: 'https://plchldr.co/i/70x50',
86
84
  },
@@ -91,14 +89,6 @@ const articleData: ArticleProps = {
91
89
  gscId: '4320982',
92
90
  }
93
91
 
94
- // remove this variable once SITE_HOST is refactored
95
- jest.mock('../../../config', () => ({
96
- siteHost: 'https://newskit-render.ceng-dev.newsuk.tech',
97
- }))
98
-
99
- jest.mock('@newskit-render/api', () => ({
100
- acsSessionUrl: 'acsSessionUrl',
101
- }))
102
92
  jest.mock('@newskit-render/my-account', () => {
103
93
  return {
104
94
  PastDueBannerExternal: 'PastDueBannerExternal',
@@ -14,7 +14,6 @@ describe('getSanitizedConfig', () => {
14
14
  it('should return required config values', () => {
15
15
  process.env = {
16
16
  ...originalEnv,
17
- SITE_HOST: 'host',
18
17
  NEWSKIT_API_ENV_URL: 'url',
19
18
  NEWSKIT_API_X_API_KEY: 'key',
20
19
  OKTA_CLIENT_ID: 'oktaId',
@@ -40,7 +39,6 @@ describe('getSanitizedConfig', () => {
40
39
  it('should throw error when NEWSKIT_API_ENV_URL is missing', () => {
41
40
  process.env = {
42
41
  ...originalEnv,
43
- SITE_HOST: 'host',
44
42
  NEWSKIT_API_X_API_KEY: 'key',
45
43
  OKTA_CLIENT_ID: 'oktaId',
46
44
  OKTA_CLIENT_SECRET: 'oktasecret',
@@ -1,5 +1,4 @@
1
1
  const requiredConfigFields: string[] = [
2
- 'SITE_HOST',
3
2
  'NEWSKIT_API_ENV_URL',
4
3
  'NEWSKIT_API_X_API_KEY',
5
4
  'OKTA_CLIENT_ID',
@@ -25,7 +24,6 @@ export const getSanitizedConfig = () => {
25
24
  newskitApiEnvUrl: process.env.NEWSKIT_API_ENV_URL as string,
26
25
  newskitApiXApiKey: process.env.NEWSKIT_API_X_API_KEY as string,
27
26
  optimizelysdkKey: process.env.OPTIMIZELY_SDK_KEY as string,
28
- siteHost: process.env.SITE_HOST as string,
29
27
  sitemapFirstPublicationDate: process.env
30
28
  .SITEMAP_FIRST_PUBLICATION_DATE as string,
31
29
  sitemapPublicationName: process.env.SITEMAP_PUBLICATION_NAME as string,
@@ -54,7 +52,6 @@ export const {
54
52
  newskitApiEnvUrl,
55
53
  newskitApiXApiKey,
56
54
  optimizelysdkKey,
57
- siteHost,
58
55
  sitemapFirstPublicationDate,
59
56
  sitemapPublicationName,
60
57
  newRelicEnabled,
@@ -1,3 +1,2 @@
1
- import { siteHost } from '../config'
2
-
3
- export const ACCOUNT_QUERY_URL = `${siteHost}/api/account/query`
1
+ export const getAccountQueryUrl = (siteHost: string): string =>
2
+ `${siteHost}/api/account/query`
@@ -3,7 +3,3 @@
3
3
  // expect(element).toHaveTextContent(/react/i)
4
4
  // learn more: https://github.com/testing-library/jest-dom
5
5
  import '@testing-library/jest-dom/extend-expect'
6
-
7
-
8
- // remove this variable once SITE_HOST is refactored
9
- process.env.SITE_HOST = 'https://newskit-render.ceng-dev.newsuk.tech'
@@ -8,7 +8,6 @@ revisionHistoryLimit: 3
8
8
 
9
9
  envs:
10
10
  NEWSKIT_API_ENV_URL: 'https://newskit.dev.newsapis.co.uk/graphql'
11
- SITE_HOST: ''
12
11
  PUBLISHER: ''
13
12
  TITLE: ''
14
13
  SITEMAP_PUBLICATION_NAME: ''
@@ -8,7 +8,6 @@ revisionHistoryLimit: 3
8
8
 
9
9
  envs:
10
10
  NEWSKIT_API_ENV_URL: 'https://newskit.dev.newsapis.co.uk/graphql'
11
- SITE_HOST: ''
12
11
  PUBLISHER: ''
13
12
  TITLE: ''
14
13
  SITEMAP_PUBLICATION_NAME: ''
@@ -8,7 +8,6 @@ revisionHistoryLimit: 5
8
8
 
9
9
  envs:
10
10
  NEWSKIT_API_ENV_URL: 'https://newskit.newsapis.co.uk/graphql'
11
- SITE_HOST: ''
12
11
  PUBLISHER: ''
13
12
  TITLE: ''
14
13
  SITEMAP_PUBLICATION_NAME: ''
@@ -8,7 +8,6 @@ revisionHistoryLimit: 5
8
8
 
9
9
  envs:
10
10
  NEWSKIT_API_ENV_URL: 'https://newskit.staging.newsapis.co.uk/graphql'
11
- SITE_HOST: ''
12
11
  PUBLISHER: ''
13
12
  TITLE: ''
14
13
  SITEMAP_PUBLICATION_NAME: ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newskit-render/core",
3
- "version": "1.79.1",
3
+ "version": "1.79.2-alpha.0",
4
4
  "description": "Newskit Render - Core package",
5
5
  "author": "",
6
6
  "license": "UNLICENSED",
@@ -33,14 +33,14 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@apollo/client": "3.4.16",
36
- "@newskit-render/api": "^0.36.0",
36
+ "@newskit-render/api": "^0.36.1-alpha.0",
37
37
  "@newskit-render/auth": "^0.44.0",
38
- "@newskit-render/checkout": "^0.51.5",
38
+ "@newskit-render/checkout": "^0.51.6-alpha.0",
39
39
  "@newskit-render/feature-flags": "^0.24.0",
40
40
  "@newskit-render/feed": "^0.24.0",
41
41
  "@newskit-render/my-account": "^0.184.0",
42
- "@newskit-render/shared-components": "^0.68.0",
43
- "@newskit-render/standalone-components": "^0.33.0",
42
+ "@newskit-render/shared-components": "^0.68.1-alpha.0",
43
+ "@newskit-render/standalone-components": "^0.33.1-alpha.0",
44
44
  "@newskit-render/validation": "^0.50.0",
45
45
  "cross-fetch": "3.1.5",
46
46
  "graphql": "15.6.0",
@@ -8,13 +8,13 @@ import {
8
8
  } from '@newskit-render/api'
9
9
  import { UserData } from '@newskit-render/my-account'
10
10
  import { Article } from '@newskit-render/standalone-components'
11
+ import { getHost } from '@newskit-render/shared-components'
11
12
  import { GET_UNIVERSAL_ARTICLE } from '../../../queries'
12
13
  import ArticlePage, { UniversalArticle } from '../../../components/article'
13
14
  import { fetchUser } from '../../../helpers/getUser'
14
- import { ACCOUNT_QUERY_URL } from '../../../constants'
15
+ import { getAccountQueryUrl } from '../../../constants'
15
16
  import { addCacheHeaders } from '../../../helpers/addCacheHeaders'
16
17
  import {
17
- siteHost as configSiteHost,
18
18
  twitterUsername as configTwitterUsername,
19
19
  gscId as configGscId,
20
20
  } from '../../../config'
@@ -43,16 +43,16 @@ const Article: React.FC<ArticleSlug> = ({
43
43
  if (typeof window !== 'undefined') {
44
44
  userId = window?.utag?.data['cp.utag_main_v_id']
45
45
  }
46
- const highlitedArticles = []
47
- const relatedArticles = []
46
+ let highlitedArticles = []
47
+ let relatedArticles = []
48
48
  const { data: recommendations } = useSWR<Article[]>(
49
49
  `/api/recommendations/${articleId}/${userId}`,
50
50
  fetcher
51
51
  )
52
52
 
53
53
  if (Array.isArray(recommendations)) {
54
- highlitedArticles.push(recommendations.slice(0, 4))
55
- relatedArticles.push(recommendations.slice(4, 12))
54
+ highlitedArticles = recommendations.slice(0, 4)
55
+ relatedArticles = recommendations.slice(4, 12)
56
56
  }
57
57
  return (
58
58
  <ArticlePage
@@ -73,7 +73,7 @@ export async function getServerSideProps(context) {
73
73
  const acsCookie = context.req.headers.cookie
74
74
  ? getAcsCookie(ClientTypes.main, context.req.headers.cookie)
75
75
  : ''
76
-
76
+ const siteHost = getHost(context.req)
77
77
  const {
78
78
  params: { articleId, section, articleSlug },
79
79
  } = context
@@ -87,16 +87,16 @@ export async function getServerSideProps(context) {
87
87
  query: GET_UNIVERSAL_ARTICLE,
88
88
  variables: { publisher: 'DEMO', id: articleId },
89
89
  }),
90
- await fetchUser(acsCookie, ACCOUNT_QUERY_URL),
90
+ await fetchUser(acsCookie, getAccountQueryUrl(siteHost)),
91
91
  ])
92
92
 
93
93
  addCacheHeaders(context.res)
94
94
  return {
95
95
  props: {
96
96
  universalArticle: data.universalArticle,
97
- articleURL: `${configSiteHost}/${section}/${articleId}/${articleSlug}`,
97
+ articleURL: `${siteHost}/${section}/${articleId}/${articleSlug}`,
98
98
  twitterUsername: configTwitterUsername || '',
99
- siteHost: configSiteHost || '',
99
+ siteHost,
100
100
  gscId: configGscId || '',
101
101
  showAds: true,
102
102
  user,
@@ -3,10 +3,11 @@ import newrelic from 'newrelic'
3
3
  import useSWR from 'swr'
4
4
  import { getAcsCookie, ClientTypes } from '@newskit-render/api'
5
5
  import { Article } from '@newskit-render/standalone-components'
6
+ import { getHost } from '@newskit-render/shared-components'
6
7
  import { Block, Cell, TitleBar } from 'newskit'
7
8
  import { UserData } from '@newskit-render/my-account'
8
9
  import { fetchUser } from '../../../helpers/getUser'
9
- import { ACCOUNT_QUERY_URL } from '../../../constants'
10
+ import { getAccountQueryUrl } from '../../../constants'
10
11
  import { addCacheHeaders } from '../../../helpers/addCacheHeaders'
11
12
  import Layout from '../../../components/layout'
12
13
  import { BasicRow } from '../../../components/section/layouts'
@@ -26,14 +27,14 @@ const RelatedArticlesPage: React.FC<RelatedArticles> = ({
26
27
  userId = window?.utag?.data['cp.utag_main_v_id']
27
28
  }
28
29
 
29
- const recommendations = []
30
+ let recommendations = []
30
31
  const { data: recommendationData } = useSWR<Article[]>(
31
32
  `/api/recommendations/${articleId}/${userId}`,
32
33
  fetcher
33
34
  )
34
35
 
35
36
  if (Array.isArray(recommendationData)) {
36
- recommendations.push(recommendationData.slice(0, 4))
37
+ recommendations = recommendationData.slice(0, 4)
37
38
  }
38
39
  return (
39
40
  <Layout dataTestId="SectionGrid" user={user}>
@@ -71,17 +72,16 @@ export async function getServerSideProps(context) {
71
72
  newrelic.setTransactionName('RelatedArticlesPage')
72
73
  console.warn('context:')
73
74
  console.warn(context.req && context.req.headers)
74
-
75
75
  const {
76
76
  params: { articleId },
77
77
  } = context
78
-
78
+ const siteHost = getHost(context.req)
79
79
  const acsCookie = context.req.headers.cookie
80
80
  ? getAcsCookie(ClientTypes.main, context.req.headers.cookie)
81
81
  : ''
82
82
 
83
83
  const [user] = await Promise.all([
84
- await fetchUser(acsCookie, ACCOUNT_QUERY_URL),
84
+ await fetchUser(acsCookie, getAccountQueryUrl(siteHost)),
85
85
  ])
86
86
 
87
87
  addCacheHeaders(context.res)
@@ -4,10 +4,11 @@ import {
4
4
  getAcsCookie,
5
5
  ClientTypes,
6
6
  } from '@newskit-render/api'
7
+ import { getHost } from '@newskit-render/shared-components'
7
8
  import { GET_PAGE } from '../../queries'
8
9
  import SectionPage from '../../components/section'
9
10
  import { fetchUser } from '../../helpers/getUser'
10
- import { ACCOUNT_QUERY_URL } from '../../constants'
11
+ import { getAccountQueryUrl } from '../../constants'
11
12
  import { addCacheHeaders } from '../../helpers/addCacheHeaders'
12
13
 
13
14
  export async function getServerSideProps(context) {
@@ -20,7 +21,7 @@ export async function getServerSideProps(context) {
20
21
  const acsCookie = context.req.headers.cookie
21
22
  ? getAcsCookie(ClientTypes.main, context.req.headers.cookie)
22
23
  : ''
23
-
24
+ const siteHost = getHost(context.req)
24
25
  newrelic.setTransactionName(`Section: ${section}`)
25
26
 
26
27
  let data
@@ -31,7 +32,7 @@ export async function getServerSideProps(context) {
31
32
  query: GET_PAGE,
32
33
  variables: { channel: section, publisher: 'DEMO' },
33
34
  }),
34
- await fetchUser(acsCookie, ACCOUNT_QUERY_URL),
35
+ await fetchUser(acsCookie, getAccountQueryUrl(siteHost)),
35
36
  ])
36
37
  data = pageData
37
38
  user = pageUser
package/pages/api/feed.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import { NextApiRequest, NextApiResponse } from 'next'
2
2
  import { rssFeed, UpdatePeriod } from '@newskit-render/feed'
3
3
  import { Publisher } from '@newskit-render/api'
4
- import { publisher, siteHost } from '../../config'
4
+ import { getHost } from '@newskit-render/shared-components'
5
+ import { publisher } from '../../config'
5
6
 
6
7
  const handler = async (req: NextApiRequest, res: NextApiResponse) =>
7
8
  rssFeed({
8
9
  res,
9
10
  publisher:
10
11
  publisher === 'DEMO' ? Publisher.VIRGIN : (publisher as Publisher),
11
- domain: siteHost,
12
+ domain: getHost(req) as string,
12
13
  titeAttributes: {
13
14
  title: 'Demo Site',
14
15
  link: '/feed',
@@ -1,7 +1,8 @@
1
1
  import { NextApiRequest, NextApiResponse } from 'next'
2
2
  import { newsSitemap } from '@newskit-render/feed'
3
3
  import { Publisher } from '@newskit-render/api'
4
- import { publisher, siteHost, sitemapPublicationName } from '../../config'
4
+ import { getHost } from '@newskit-render/shared-components'
5
+ import { publisher, sitemapPublicationName } from '../../config'
5
6
  /* We do not have sitemap date for Demo so using Virgin,
6
7
  * This can be removed and replace with just - publisher: process.env.PUBLISHER as PublisherGroup, in created projects
7
8
  */
@@ -11,7 +12,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) =>
11
12
  res,
12
13
  publisher:
13
14
  publisher === 'DEMO' ? Publisher.VIRGIN : (publisher as Publisher),
14
- domain: new URL(siteHost as string).host,
15
+ domain: new URL(getHost(req) as string).host,
15
16
  publicationName: sitemapPublicationName as string,
16
17
  })
17
18
 
@@ -1,9 +1,9 @@
1
1
  import { NextApiRequest, NextApiResponse } from 'next'
2
2
  import { genericSitemap, CustomStaticPage } from '@newskit-render/feed'
3
3
  import { Publisher } from '@newskit-render/api'
4
+ import { getHost } from '@newskit-render/shared-components'
4
5
  import {
5
6
  publisher,
6
- siteHost,
7
7
  sitemapFirstPublicationDate,
8
8
  sitemapPublicationName,
9
9
  } from '../../config'
@@ -22,7 +22,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) =>
22
22
  query: req.query,
23
23
  publisher:
24
24
  publisher === 'DEMO' ? Publisher.VIRGIN : (publisher as Publisher),
25
- domain: new URL(siteHost as string).host,
25
+ domain: new URL(getHost(req) as string).host,
26
26
  firstArticleDate: sitemapFirstPublicationDate as string,
27
27
  publicationName: sitemapPublicationName as string,
28
28
  customStaticPageCollection: defaultCustomStaticPagesCollection,
package/pages/index.tsx CHANGED
@@ -4,10 +4,11 @@ import {
4
4
  getAcsCookie,
5
5
  ClientTypes,
6
6
  } from '@newskit-render/api'
7
+ import { getHost } from '@newskit-render/shared-components'
7
8
  import { GET_PAGE } from '../queries'
8
9
  import SectionPage from '../components/section'
9
10
  import { fetchUser } from '../helpers/getUser'
10
- import { ACCOUNT_QUERY_URL } from '../constants'
11
+ import { getAccountQueryUrl } from '../constants'
11
12
  import { addCacheHeaders } from '../helpers/addCacheHeaders'
12
13
 
13
14
  export async function getServerSideProps(context) {
@@ -20,13 +21,13 @@ export async function getServerSideProps(context) {
20
21
  const acsCookie = context.req.headers.cookie
21
22
  ? getAcsCookie(ClientTypes.main, context.req.headers.cookie)
22
23
  : ''
23
-
24
+ const siteHost = getHost(context.req)
24
25
  const [{ data }, user] = await Promise.all([
25
26
  apolloClient.query({
26
27
  query: GET_PAGE,
27
28
  variables: { channel: 'homepage', publisher: 'DEMO' },
28
29
  }),
29
- await fetchUser(acsCookie, ACCOUNT_QUERY_URL),
30
+ await fetchUser(acsCookie, getAccountQueryUrl(siteHost)),
30
31
  ])
31
32
 
32
33
  addCacheHeaders(context.res)
@@ -15,6 +15,7 @@ import {
15
15
  CookieView,
16
16
  } from '@newskit-render/auth'
17
17
  import { createApolloClient, ClientTypes } from '@newskit-render/api'
18
+ import { getHost } from '@newskit-render/shared-components'
18
19
  import { GET_UNIVERSAL_ARTICLE } from '../../../../../queries'
19
20
  import ArticlePage from '../../../../../components/article'
20
21
  import {
@@ -23,7 +24,6 @@ import {
23
24
  } from '../../../../../helpers/mocks/articleMock'
24
25
  import { addCacheHeaders } from '../../../../../helpers/addCacheHeaders'
25
26
  import {
26
- siteHost as configSiteHost,
27
27
  twitterUsername as configTwitterUsername,
28
28
  gscId as configGscId,
29
29
  } from '../../../../../config'
@@ -90,6 +90,7 @@ const PreviewArticle = ({
90
90
  export async function getServerSideProps(context) {
91
91
  const apolloClient = await createApolloClient(ClientTypes.nkapi)
92
92
  const session = await getSession(context)
93
+ const siteHost = getHost(context.req)
93
94
  if (!session) {
94
95
  return {
95
96
  props: {},
@@ -109,9 +110,9 @@ export async function getServerSideProps(context) {
109
110
  props: {
110
111
  universalArticle: data.universalArticle,
111
112
  session,
112
- articleURL: `${configSiteHost}/preview/${articleId}/version/${versionId}`,
113
+ articleURL: `${siteHost}/preview/${articleId}/version/${versionId}`,
113
114
  twitterUsername: configTwitterUsername || '',
114
- siteHost: configSiteHost || '',
115
+ siteHost,
115
116
  gscId: configGscId || '',
116
117
  },
117
118
  }