Skip to content

Commit b9f5814

Browse files
committed
Merge branch 'master' into version-latest
2 parents adc65fb + 2aa177e commit b9f5814

File tree

17 files changed

+50
-27
lines changed

17 files changed

+50
-27
lines changed

.github/workflows/.xp-archive-deploy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
6464
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
6565
dockerfile: Dockerfile_xp
66+
image_suffix: ${{ inputs.naisEnv }}
6667
- name: Deploy application
6768
uses: nais/deploy/actions/deploy@v2
6869
env:

common/src/shared/siteConfigs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const legacyArchiveConfigs: LegacyArchiveSiteConfig[] = [
3030
] as const;
3131

3232
export const xpArchiveConfig: XpArchiveSiteConfig = {
33-
name: 'nav.no (2024)',
33+
name: 'nav.no (Enonic XP)',
3434
basePath: '/xp',
3535
type: 'enonic-xp',
3636
} as const;

legacy-archive/.env-template

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
NODE_ENV=development
22
APP_PORT=3399
33
APP_BASEPATH=/
4-
APP_ORIGIN=http://localhost:3399
4+
APP_ORIGIN_INTERNAL=http://localhost:3399
55
OPEN_SEARCH_URI=http://my-opensearch-instance
66
OPEN_SEARCH_USERNAME=username
77
OPEN_SEARCH_PASSWORD=password

legacy-archive/.nais/config.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ spec:
1111
port: 3399
1212
ingresses:
1313
- https://cms-arkiv.intern.nav.no
14+
- https://cms-arkiv.ansatt.nav.no
1415
liveness:
1516
path: /internal/isAlive
1617
initialDelay: 10
@@ -22,7 +23,7 @@ spec:
2223
value: "3399"
2324
- name: APP_BASEPATH
2425
value: "/"
25-
- name: APP_ORIGIN
26+
- name: APP_ORIGIN_INTERNAL
2627
value: "https://cms-arkiv.intern.nav.no"
2728
openSearch:
2829
access: read

legacy-archive/server/src/cms/CmsArchiveSite.ts

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type ContructorProps = {
2121
htmlRenderer: HtmlRenderer;
2222
};
2323

24+
const HOST_SUFFIX_INTERNAL = 'intern.nav.no';
25+
const HOST_SUFFIX_EXTERNAL = 'ansatt.nav.no';
26+
2427
export class CmsArchiveSite {
2528
private readonly config: LegacyArchiveSiteConfig;
2629
private readonly pdfGenerator: PdfGenerator;
@@ -113,6 +116,18 @@ export class CmsArchiveSite {
113116
}
114117

115118
private setupSiteRoutes(router: Router, htmlRenderer: HtmlRenderer) {
119+
// Redirect from internal urls
120+
router.get('*', (req, res, next) => {
121+
const { hostname, protocol, originalUrl } = req;
122+
123+
if (hostname.endsWith(HOST_SUFFIX_INTERNAL)) {
124+
const externalUrl = `${protocol}://${hostname.replace(HOST_SUFFIX_INTERNAL, HOST_SUFFIX_EXTERNAL)}${originalUrl}`;
125+
return res.redirect(externalUrl);
126+
}
127+
128+
return next();
129+
});
130+
116131
router.get('/:versionKey?', cspMiddleware, async (req, res) => {
117132
const rootCategories = this.categoriesService.getRootCategories();
118133

legacy-archive/server/src/global.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare global {
44
NODE_ENV: 'development' | 'production';
55
APP_BASEPATH: string;
66
APP_PORT: string;
7-
APP_ORIGIN: string;
7+
APP_ORIGIN_INTERNAL: string;
88
OPEN_SEARCH_URI: string;
99
OPEN_SEARCH_USERNAME: string;
1010
OPEN_SEARCH_PASSWORD: string;

legacy-archive/server/src/opensearch/queries/contentSearch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const buildContentSearchParams = (
7878

7979
if (query) {
8080
if (type === 'locations') {
81-
const { pathname } = new URL(query, process.env.APP_ORIGIN);
81+
const { pathname } = new URL(query, process.env.APP_ORIGIN_INTERNAL);
8282

8383
must.push({
8484
prefix: {

legacy-archive/server/src/pdf/PdfGenerator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class PdfGenerator {
123123
// Ensures assets with relative urls are loaded from the correct origin
124124
const htmlWithBase = html.replace(
125125
'<head>',
126-
`<head><base href="${process.env.APP_ORIGIN}"/>`
126+
`<head><base href="${process.env.APP_ORIGIN_INTERNAL}"/>`
127127
);
128128

129129
try {

legacy-archive/server/src/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const expectedEnv = [
99
'NODE_ENV',
1010
'APP_PORT',
1111
'APP_BASEPATH',
12-
'APP_ORIGIN',
12+
'APP_ORIGIN_INTERNAL',
1313
'OPEN_SEARCH_URI',
1414
'OPEN_SEARCH_USERNAME',
1515
'OPEN_SEARCH_PASSWORD',

xp-archive/client/contentTree/NavigationBar.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
2-
import { Heading, Loader } from '@navikt/ds-react';
2+
import { Alert, Heading, Loader } from '@navikt/ds-react';
33
import { useContentTree } from '../hooks/useContentTree';
44
import { NavigationItem } from './contentTreeEntry/NavigationItem';
55
import { SimpleTreeView } from '@mui/x-tree-view';
66

77
export const NavigationBar = () => {
8-
const { data, isLoading } = useContentTree('/');
8+
const { data, isLoading } = useContentTree('/', 'no');
99

1010
return (
1111
<div>
@@ -17,6 +17,9 @@ export const NavigationBar = () => {
1717
{data?.children.map((entry) => <NavigationItem entry={entry} key={entry.id} />)}
1818
</SimpleTreeView>
1919
)}
20+
<Alert variant={'warning'} size={'small'} inline={true} style={{ marginTop: '1.5rem' }}>
21+
{'Obs: dette arkivet er under utvikling og er ikke klart til bruk!'}
22+
</Alert>
2023
</div>
2124
);
2225
};

xp-archive/client/contentTree/contentTreeEntry/NavigationItem.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ export const NavigationItem = ({ entry }: Props) => {
2727
setSelectedContentId(entry.id);
2828
}}
2929
>
30-
{entry.numChildren > 0 ? <NavigationItems path={entry.path} /> : null}
30+
{entry.numChildren > 0 ? (
31+
<NavigationItems path={entry.path} locale={entry.locale} />
32+
) : null}
3133
</TreeItem>
3234
);
3335
};
3436

35-
const NavigationItems = ({ path }: { path: string }) => {
36-
const { data, isLoading } = useContentTree(path);
37+
const NavigationItems = ({ path, locale }: { path: string; locale: string }) => {
38+
const { data, isLoading } = useContentTree(path, locale);
3739
return (
3840
<>
3941
{isLoading ? (

xp-archive/client/contentView/ContentView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const ContentView = () => {
3232

3333
const { data, isLoading } = useFetchContent({
3434
id: fetchId || '',
35-
version: selectedVersion?.versionId ?? undefined,
35+
versionId: selectedVersion?.versionId ?? undefined,
3636
});
3737

3838
const [selectedView, setSelectedView] = useState<ViewVariant>('json');

xp-archive/client/hooks/useContentTree.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { XPContentTreeServiceResponse } from '../../shared/types';
44

55
const CONTENT_TREE_API = `${import.meta.env.VITE_APP_ORIGIN}/xp/api/contentTree`;
66

7-
const fetchContentTree = async (path: string) => {
8-
return fetchJson<XPContentTreeServiceResponse>(CONTENT_TREE_API, { params: { path } });
7+
const fetchContentTree = async ({ path, locale }: { path: string; locale: string }) => {
8+
return fetchJson<XPContentTreeServiceResponse>(CONTENT_TREE_API, { params: { path, locale } });
99
};
1010

11-
export const useContentTree = (path: string) => {
12-
return useSWRImmutable(path, fetchContentTree);
11+
export const useContentTree = (path: string, locale: string) => {
12+
return useSWRImmutable({ path, locale }, fetchContentTree);
1313
};

xp-archive/client/hooks/useFetchContent.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ContentServiceResponse } from '../../shared/types';
44

55
const CONTENT_API = `${import.meta.env.VITE_APP_ORIGIN}/xp/api/content`;
66

7-
type FetchContentParams = { id: string; version?: string };
7+
type FetchContentParams = { id: string; versionId?: string };
88

99
const fetchContent = async (params: FetchContentParams) => {
1010
if (!params.id) return;
@@ -13,6 +13,6 @@ const fetchContent = async (params: FetchContentParams) => {
1313
});
1414
};
1515

16-
export const useFetchContent = ({ id, version }: FetchContentParams) => {
17-
return useSWRImmutable({ id, version }, fetchContent);
16+
export const useFetchContent = ({ id, versionId }: FetchContentParams) => {
17+
return useSWRImmutable({ id, versionId }, fetchContent);
1818
};

xp-archive/server/src/services/ContentService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class ContentService {
5757
'Content-Type': 'application/json',
5858
},
5959
method: 'POST',
60-
body: JSON.stringify({ contentProps }),
60+
body: JSON.stringify({ contentProps: { ...contentProps, noRedirect: true } }),
6161
});
6262
}
6363
}

xp-archive/server/src/services/ContentTreeService.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ export class ContentTreeService {
88
private readonly CONTENT_TREE_API = xpServiceUrl('externalArchive/contentTree');
99

1010
public getContentTreeHandler: RequestHandler = async (req, res) => {
11-
if (!validateQuery(req.query, ['path'])) {
12-
return res.status(400).send('Parameter path is required');
11+
if (!validateQuery(req.query, ['path', 'locale'])) {
12+
return res.status(400).send('Parameters path and locale are required');
1313
}
1414

15-
const { path } = req.query;
15+
const { path, locale } = req.query;
1616

17-
const contentTreeResponse = await this.fetchContentTree(path);
17+
const contentTreeResponse = await this.fetchContentTree(path, locale);
1818

1919
return res.status(200).json(contentTreeResponse);
2020
};
2121

22-
private async fetchContentTree(path: string) {
22+
private async fetchContentTree(path: string, locale: string) {
2323
const response = await fetchJson<XPContentTreeServiceResponse>(this.CONTENT_TREE_API, {
2424
headers: { secret: process.env.SERVICE_SECRET },
25-
params: { path, locale: 'no' }, // TODO: ikke hardkode locale
25+
params: { path, locale },
2626
});
2727

2828
return response;

xp-archive/shared/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type ContentTreeEntryData = {
66
name: string;
77
displayName: string;
88
type: string;
9+
locale: string;
910
numChildren: number;
1011
isLocalized: boolean;
1112
hasLocalizedDescendants: boolean;

0 commit comments

Comments
 (0)