Skip to content

Commit fbd87d7

Browse files
committed
Fix rendering in view mode
1 parent 6df2927 commit fbd87d7

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

samples/musicfestival-frontend-react/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
REACT_APP_CG_PROXY_URL=http://localhost:8082/EpiServer/ContentGraph/CGProxy/Query
1+
REACT_APP_CG_PREVIEW_URL=https://cg.optimizely.com/content/v2
22
REACT_APP_CONTENT_GRAPH_GATEWAY_URL=https://cg.optimizely.com/content/v2?auth=INPUT_SINGLE_KEY_HERE
33

44
REACT_APP_LOGIN_AUTHORITY=http://localhost:8082

samples/musicfestival-frontend-react/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { BlockPage } from './pages/BlockPage';
1616

1717
let previousSavedMessage: any = null;
1818
const singleKeyUrl = process.env.REACT_APP_CONTENT_GRAPH_GATEWAY_URL as string
19-
const hmacKeyUrl = process.env.REACT_APP_CG_CONTENT_URL as string
19+
const hmacKeyUrl = process.env.REACT_APP_CG_PREVIEW_URL as string
2020

2121
const App = () => {
2222
const queryClient = useQueryClient();

samples/musicfestival-frontend-react/src/helpers/urlHelper.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ const getImageUrl = (path = "") => {
1818
}
1919

2020
const extractParams = (token: string, urlPath: string) => {
21-
const base64String = token.substring(token.indexOf('.') + 1, token.lastIndexOf('.'));
22-
const payload: Payload = JSON.parse(Buffer.from(base64String, 'base64').toString());
21+
var payload: Payload = {
22+
c_id: undefined,
23+
c_ver: undefined
24+
};
2325

26+
if (token) {
27+
const base64String = token.substring(token.indexOf('.') + 1, token.lastIndexOf('.'));
28+
payload = JSON.parse(Buffer.from(base64String, 'base64').toString());
29+
}
30+
2431
let relativePath = (urlPath.length > 1 && urlPath != "/search") ? urlPath : '/en'
2532

2633
const epiContentPrefix = "/EPiServer/CMS/Content/";
@@ -43,7 +50,10 @@ const extractParams = (token: string, urlPath: string) => {
4350
const urlSegments = relativePath.split('/')
4451
const language = urlSegments.length ? urlSegments.find(s => s.length === 2) : "en"
4552

46-
return { relativePath, locales: language, language, contentId: parseInt(payload.c_id.toString()) , workId: parseInt(payload.c_ver.toString()) }
53+
const contentId = payload.c_id && parseInt(payload.c_id!.toString());
54+
const workId = payload.c_ver && parseInt(payload.c_ver!.toString());
55+
56+
return { relativePath, locales: language, language, contentId: contentId, workId: workId }
4757
}
4858

4959
const getRankingFromSearchParams = (searchParams: URLSearchParams): Ranking => {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export interface Payload {
2-
c_id: number;
3-
c_ver: number;
2+
c_id?: number;
3+
c_ver?: number;
44
}

samples/musicfestival-frontend-react/src/pages/SearchPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { subcribeContentSavedEvent } from "../helpers/contentSavedEvent";
2121

2222
let previousSavedMessage: any = null;
2323
const singleKeyUrl = process.env.REACT_APP_CONTENT_GRAPH_GATEWAY_URL as string
24-
const hmacKeyUrl = process.env.REACT_APP_CG_CONTENT_URL as string
24+
const hmacKeyUrl = process.env.REACT_APP_CG_PREVIEW_URL as string
2525

2626
function SearchPage() {
2727
console.log("Start")

0 commit comments

Comments
 (0)