Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛂 Config for å tillate spørringer fra mikrofrontend #275

Merged
merged 9 commits into from
Feb 15, 2024
16 changes: 16 additions & 0 deletions pages/api/soknader/soknaderInnsending.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import { beskyttetApi, getAccessTokenFromRequest } from '@navikt/aap-felles-utils';
import { getSøknaderInnsending } from 'pages/api/soknader/soknader';

const allowedOrigins = [
'https://www.intern.dev.nav.no',
'https://aap-mine-aap.intern.dev.nav.no',
'https://www.nav.no',
];

const handler = beskyttetApi(async (req, res) => {
const accessToken = getAccessTokenFromRequest(req);
const søknader = await getSøknaderInnsending(accessToken);
if (req.headers.origin) {
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Access-Control-Allow-Origin', allowedOrigins.includes(req.headers.origin) ? req.headers.origin : '');
res.setHeader('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT');
res.setHeader(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
);
}

res.status(200).json(søknader);
});

Expand Down
Loading