-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.middleware.ts
108 lines (96 loc) · 4.5 KB
/
vite.middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { ViteDevServer } from 'vite';
import axios from 'axios';
const envProperties = {
APIGW_URL: process.env.APIGW_URL || 'http://localhost:8080',
APIGW_HEADER: process.env.APIGW_HEADER,
LOGIN_URL: process.env.LOGIN_URL || '/tiltaksgjennomforing/fakelogin/aad',
LOGOUT_URL: process.env.LOGOUT_URL || '/tiltaksgjennomforing/fakelogout?domain=localhost',
STILLINGSTITLER_URL: process.env.STILLINGSTITLER_URL || 'https://tiltak-stillingstitler.intern.dev.nav.no',
};
export default () => ({
name: 'configure-server',
configureServer(server: ViteDevServer) {
const { middlewares } = server;
server.middlewares.use('/tiltaksgjennomforing/innloggingskilder', (_, res) => {
const innloggingskilder = [
{
tittel: 'Som deltaker',
part: 'DELTAKER',
url: '/tiltaksgjennomforing/fakelogin/tokenx',
},
{
tittel: 'Som mentor',
part: 'MENTOR',
url: '/tiltaksgjennomforing/fakelogin/tokenx',
},
{
tittel: 'Som arbeidsgiver',
part: 'ARBEIDSGIVER',
url: '/tiltaksgjennomforing/fakelogin/tokenx',
},
{
tittel: 'Som veileder',
part: 'VEILEDER',
url: '/tiltaksgjennomforing/fakelogin/aad',
},
{
tittel: 'Som beslutter',
part: 'BESLUTTER',
url: '/tiltaksgjennomforing/fakelogin/aad',
},
];
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(innloggingskilder));
});
middlewares.use('/tiltaksgjennomforing/logout', async (_, res) => {
res.writeHead(302, { Location: envProperties.LOGOUT_URL as string });
res.end();
});
middlewares.use('/tiltaksgjennomforing/fakelogin/tokenx', async (req, res) => {
const subject = req.headers['fnr'] || '23090170716';
const url = `https://tiltak-fakelogin.ekstern.dev.nav.no/token?iss=tokenx&aud=fake-tokenx&pid=${subject}&acr=Level4`;
const response = await axios.get(url);
res.setHeader('set-cookie', `fake-tokenx-idtoken=${response.data};path=/`);
res.writeHead(302, { Location: '/tiltaksgjennomforing' });
res.end();
});
middlewares.use('/tiltaksgjennomforing/fakelogin/aad', async (req, res) => {
const navIdent = req.headers['navident'] || 'Z123456';
const url = `https://tiltak-fakelogin.ekstern.dev.nav.no/token?iss=aad&aud=fake-aad&NAVident=${navIdent}`;
const response = await axios.get(url);
res.setHeader('set-cookie', `fake-aad-idtoken=${response.data};path=/`);
res.writeHead(302, { Location: '/tiltaksgjennomforing' });
res.end();
});
middlewares.use('/tiltaksgjennomforing/chat', async (req, res) => {
const redirectUrl = process.env.ARBEIDSGIVER_DIALOG_URL;
const searchParams = new URLSearchParams(req.url);
const orgNr = searchParams.get('organisasjonsnummer');
const avtaleNr = searchParams.get('avtalenummer');
res.writeHead(302, {
Location: `${redirectUrl}/?organisasjonsnummer=${orgNr}&avtalenummer=${avtaleNr}`,
});
res.end();
});
middlewares.use('/tiltaksgjennomforing/brukavInternflate', async (_, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(process.env.ENABLE_INTERNAL_MENU === 'true'));
});
middlewares.use('/tiltaksgjennomforing/fakelogout', async (_, res) => {
res.setHeader('set-cookie', [
'fake-tokenx-idtoken=; max-age=0; path=/',
'fake-aad-idtoken=; max-age=0; path=/',
]);
res.writeHead(302, { Location: '/tiltaksgjennomforing' });
res.end();
});
middlewares.use('/tiltaksgjennomforing/skal-backupmeny-brukes', async (_, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(
JSON.stringify(
process.env.ENABLE_EXTERNAL_MENU !== 'true' && process.env.ENABLE_INTERNAL_MENU !== 'true',
),
);
});
},
});