Skip to content

Commit

Permalink
tc-53 refaktorering av headers
Browse files Browse the repository at this point in the history
  • Loading branch information
taniaholst committed Apr 1, 2022
1 parent 34e04df commit 80bb8b0
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
6 changes: 1 addition & 5 deletions frontend/mulighetsrommet-veileder-flate/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { ALL_TOGGLES, Features } from './features';
import useFetch from '@nutgaard/use-fetch';
import { APP_NAME } from '../utils/constants';

const headers = {
headers: { 'Nav-Consumer-Id': APP_NAME },
};
import { headers } from './utils';

const toggles = ALL_TOGGLES.map(element => 'feature=' + element).join('&');

Expand Down
10 changes: 5 additions & 5 deletions frontend/mulighetsrommet-veileder-flate/src/api/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import {
createMockFrontendLogger,
DEFAULT_FRONTENDLOGGER_API_URL,
} from '@navikt/frontendlogger/lib';
import { APP_NAME } from '../utils/constants';
import { LOG_NAME } from '../constants';

export const logger = import.meta.env.DEV
? createMockFrontendLogger(APP_NAME)
: createFrontendLogger(APP_NAME, DEFAULT_FRONTENDLOGGER_API_URL);
? createMockFrontendLogger(LOG_NAME)
: createFrontendLogger(LOG_NAME, DEFAULT_FRONTENDLOGGER_API_URL);

export const logError = (fields?: {}, tags?: {}): void => {
logger.event(`${APP_NAME}.error`, fields, tags);
logger.event(`${LOG_NAME}.error`, fields, tags);
};

export const logMetrikk = (metrikkNavn: string, fields?: {}, tags?: {}): void => {
logger.event(`${APP_NAME}.metrikker.${metrikkNavn}`, fields, tags);
logger.event(`${LOG_NAME}.metrikker.${metrikkNavn}`, fields, tags);
};

export const logEvent = (logTag: string, fields?: {}, tags?: {}): void => {
Expand Down
5 changes: 5 additions & 0 deletions frontend/mulighetsrommet-veileder-flate/src/api/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { hasData as _hasData, WithData, WithError, WithoutData } from '@nutgaard/use-fetch';
import { APPLICATION_NAME } from '../constants';

type AsyncData<TYPE> = WithoutData | WithData<TYPE> | WithError;

// Midlertidig fix for at hasData fra useFetch sjekker status og ikke at data er lastet inn
export function hasData<TYPE>(result: AsyncData<TYPE>): result is WithData<TYPE> {
return (result as WithData<TYPE>).data != null && _hasData(result);
}

export const headers = {
headers: { 'Nav-Consumer-Id': APPLICATION_NAME },
};
2 changes: 1 addition & 1 deletion frontend/mulighetsrommet-veileder-flate/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const APPLICATION_NAME = 'mulighetsrommet-veileder-flate';

export const LOG_NAME = 'mulighetsrommet';
/**
* The id references an HTML tag available through `veilarbpersonflatefs`, in which this application
* gets mounted.
Expand Down
6 changes: 3 additions & 3 deletions frontend/mulighetsrommet-veileder-flate/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { OpenAPI } from 'mulighetsrommet-api-client';
import Navspa from '@navikt/navspa';
import { worker } from './mock/worker';
import { APPLICATION_NAME } from './constants';
import { headers } from './api/utils';

OpenAPI.HEADERS = headers.headers;

OpenAPI.HEADERS = {
'Nav-Consumer-Id': APPLICATION_NAME,
};
OpenAPI.BASE = String(import.meta.env.VITE_MULIGHETSROMMET_API_BASE ?? '');

if (import.meta.env.VITE_MULIGHETSROMMET_API_MOCK === 'true') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { Features, ALERT_INFO, FAKE_DOOR } from '../../api/features';

export const mockFeatures: Features = {
[ALERT_INFO]: true,
[FAKE_DOOR]: true,
[FAKE_DOOR]: false,
};

This file was deleted.

0 comments on commit 80bb8b0

Please sign in to comment.