-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.ts
91 lines (76 loc) · 2.84 KB
/
server.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
import './konfigurerApp';
import path from 'path';
import { json, urlencoded, NextFunction, Request, Response } from 'express';
import expressStaticGzip from 'express-static-gzip';
import { v4 as uuidv4 } from 'uuid';
// eslint-disable-next-line
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import backend, { IApp, ensureAuthenticated, envVar } from '@navikt/familie-backend';
import { logInfo } from '@navikt/familie-logging';
import { oboHistorikkConfig, oboTilbakeConfig, sessionConfig } from './config';
import { prometheusTellere } from './metrikker';
import {
attachToken,
doHistorikkApiProxy,
doHistorikkStreamProxy,
doPdfProxy,
doProxy,
doRedirectProxy,
} from './proxy';
import setupRouter from './router';
import config from '../../src/webpack/webpack.dev';
const port = 8000;
backend(sessionConfig, prometheusTellere).then(({ app, azureAuthClient, router }: IApp) => {
let middleware;
if (process.env.NODE_ENV === 'development') {
const compiler = webpack(config);
middleware = webpackDevMiddleware(compiler, {
publicPath: config.output?.publicPath,
writeToDisk: true,
});
app.use(middleware);
// @ts-ignore
app.use(webpackHotMiddleware(compiler));
} else {
app.use('/assets', expressStaticGzip(path.join(process.cwd(), 'frontend_production'), {}));
}
app.use((req: Request, _res: Response, next: NextFunction) => {
req.headers['nav-call-id'] = uuidv4();
req.headers['nav-consumer-id'] = 'familie-tilbake-frontend';
next();
});
app.use(
'/familie-historikk/stream',
ensureAuthenticated(azureAuthClient, true),
attachToken(azureAuthClient, oboHistorikkConfig),
doHistorikkStreamProxy()
);
app.use(
'/familie-historikk/api',
ensureAuthenticated(azureAuthClient, true),
attachToken(azureAuthClient, oboHistorikkConfig),
doHistorikkApiProxy()
);
app.use(
'/familie-tilbake/api/pdf',
ensureAuthenticated(azureAuthClient, true),
attachToken(azureAuthClient, oboTilbakeConfig),
doPdfProxy()
);
app.use(
'/familie-tilbake/api',
ensureAuthenticated(azureAuthClient, true),
attachToken(azureAuthClient, oboTilbakeConfig),
doProxy()
);
app.use('/redirect', doRedirectProxy());
// Sett opp express og router etter proxy. Spesielt viktig med tanke på større payloads
app.use(json({ limit: '200mb' }));
app.use(urlencoded({ limit: '200mb', extended: true }));
app.use('/', setupRouter(azureAuthClient, router));
app.listen(port, '0.0.0.0', () => {
logInfo(`Server startet på port ${port}. Build version: ${envVar('APP_VERSION')}.`);
});
});