-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bruke common server i oms-arb (#2270)
* Serveroppsett * Changesets * changelog
- Loading branch information
1 parent
4172f35
commit 39fb296
Showing
92 changed files
with
581 additions
and
1,001 deletions.
There are no files selected for viewing
20 changes: 12 additions & 8 deletions
20
apps/omsorgspengerutbetaling-arbeidstaker-soknad/.env.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
API_URL=http://localhost:8089 | ||
APPSTATUS_DATASET=staging | ||
APPSTATUS_PROJECT_ID=ryujtq87 | ||
DEKORATOR_URL=https://dekoratoren.ekstern.dev.nav.no/?simple=true&chatbot=false&urlLookupTable=false&logoutUrl=https://omsorgspengerutbetaling-arbeidstaker-soknad.intern.dev.nav.no/oauth2/logout&redirectToApp=true, | ||
FRONTEND_API_PATH=http://localhost:8089 | ||
FRONTEND_VEDLEGG_URL=http://localhost:8080/api | ||
LOGIN_URL=http://localhost:8089 | ||
MINSIDE_URL=https://www.intern.dev.nav.no/minside | ||
APP_VERSION=dev | ||
NODE_ENV=development | ||
PUBLIC_PATH=/familie/sykdom-i-familien/soknad/omsorgspengerutbetaling-arbeidstaker | ||
GITHUB_REF_NAME=branch-name | ||
|
||
SIF_PUBLIC_APPSTATUS_DATASET=staging | ||
SIF_PUBLIC_APPSTATUS_PROJECT_ID=ryujtq87 | ||
SIF_PUBLIC_DEKORATOR_URL=https://www.nav.no/dekoratoren/?simple=true&chatbot=false&logoutUrl=https://www.nav.no/familie/sykdom-i-familien/soknad/omsorgspengerutbetaling/oauth2/logout | ||
SIF_PUBLIC_LOGIN_URL=http://localhost:8081/auth-mock/cookie?subject=mockSubject&redirect_location=http://localhost:8080 | ||
SIF_PUBLIC_MINSIDE_URL=https://www.intern.dev.nav.no/minside | ||
|
||
K9_BRUKERDIALOG_PROSESSERING_FRONTEND_PATH=/familie/sykdom-i-familien/soknad/omsorgspengerutbetaling-arbeidstaker/api | ||
K9_BRUKERDIALOG_PROSESSERING_API_SCOPE=dev-gcp:dusseldorf:k9-brukerdialog-prosessering | ||
K9_BRUKERDIALOG_PROSESSERING_API_URL=http://k9-brukerdialog-prosessering |
13 changes: 13 additions & 0 deletions
13
apps/omsorgspengerutbetaling-arbeidstaker-soknad/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 69 additions & 26 deletions
95
apps/omsorgspengerutbetaling-arbeidstaker-soknad/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,78 @@ | ||
FROM node:20.12-alpine AS base | ||
|
||
FROM node:18-alpine AS base | ||
RUN apk update && apk add git | ||
RUN apk add --no-cache libc6-compat | ||
ENV APP="omsorgspengerutbetaling-arbeidstaker-soknad" | ||
ENV SERVER="server" | ||
ENV SCOPE=@navikt/omsorgspengerutbetaling-arbeidstaker-soknad | ||
|
||
RUN apk fix \ | ||
&& apk add --no-cache --update libc6-compat tini \ | ||
&& rm -rf /var/cache/apk/* | ||
|
||
RUN yarn global add turbo | ||
|
||
######################################### | ||
# PREPARE DEPS FOR BUILD | ||
######################################### | ||
|
||
FROM base AS prepare | ||
WORKDIR /app | ||
COPY ["package.json", ".yarnrc.yml", "yarn.lock", "turbo.json", "./"] | ||
COPY [".yarn/releases/*", ".yarn/releases/"] | ||
COPY packages packages | ||
COPY apps apps | ||
ARG SERVER | ||
COPY ${SERVER} ${SERVER} | ||
RUN find apps \! -name "package.json" -mindepth 2 -maxdepth 2 -print | xargs rm -rf | ||
RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -print | xargs rm -rf | ||
RUN find ${SERVER} \! -name "package.json" -mindepth 2 -maxdepth 2 -print | xargs rm -rf | ||
|
||
ENV SCOPE=@navikt/omsorgspengerutbetaling-arbeidstaker-soknad | ||
######################################### | ||
# BUILDER IMAGE - INSTALL PACKAGES AND COPY SOURCE | ||
######################################### | ||
|
||
FROM base AS turbo-builder | ||
FROM prepare AS installer | ||
COPY --from=prepare /app ./ | ||
RUN --mount=type=secret,id=PACKAGES_AUTH_TOKEN \ | ||
PACKAGES_AUTH_TOKEN=$(cat /run/secrets/PACKAGES_AUTH_TOKEN) yarn | ||
COPY . . | ||
RUN yarn | ||
RUN yarn turbo run build --filter=${SCOPE} | ||
|
||
FROM base AS ws-installer | ||
RUN apk update && apk add git | ||
RUN apk add --no-cache libc6-compat | ||
WORKDIR /app-ws | ||
COPY . . | ||
RUN yarn workspaces focus ${SCOPE} --production | ||
|
||
FROM gcr.io/distroless/nodejs18-debian11:nonroot | ||
WORKDIR /apps/omsorgspengerutbetaling-arbeidstaker-soknad | ||
COPY --from=ws-installer /app-ws/node_modules ./node_modules/ | ||
COPY --from=turbo-builder /app/apps/omsorgspengerutbetaling-arbeidstaker-soknad/server.cjs . | ||
COPY --from=turbo-builder /app/apps/omsorgspengerutbetaling-arbeidstaker-soknad/tokenx.cjs . | ||
COPY --from=turbo-builder /app/apps/omsorgspengerutbetaling-arbeidstaker-soknad/package.json . | ||
COPY --from=turbo-builder /app/apps/omsorgspengerutbetaling-arbeidstaker-soknad/src/build/decorator.cjs ./src/build/decorator.cjs | ||
COPY --from=turbo-builder /app/apps/omsorgspengerutbetaling-arbeidstaker-soknad/src/build/AppSettings.cjs ./src/build/AppSettings.cjs | ||
COPY --from=turbo-builder /app/apps/omsorgspengerutbetaling-arbeidstaker-soknad/dist ./dist | ||
|
||
EXPOSE 8080 | ||
CMD ["server.cjs"] | ||
######################################### | ||
# BUILD SERVER | ||
######################################### | ||
|
||
FROM installer AS server-build | ||
ARG SERVER | ||
WORKDIR /app/${SERVER} | ||
RUN --mount=type=secret,id=PACKAGES_AUTH_TOKEN \ | ||
PACKAGES_AUTH_TOKEN=$(cat /run/secrets/PACKAGES_AUTH_TOKEN) yarn build | ||
|
||
|
||
######################################### | ||
# Client | ||
######################################### | ||
|
||
FROM installer AS client-build | ||
WORKDIR /app | ||
RUN --mount=type=secret,id=PACKAGES_AUTH_TOKEN \ | ||
PACKAGES_AUTH_TOKEN=$(cat /run/secrets/PACKAGES_AUTH_TOKEN) yarn turbo run build --filter=${SCOPE} | ||
RUN mv /app/apps/${APP}/dist /public | ||
|
||
|
||
######################################### | ||
# Server | ||
######################################### | ||
FROM base AS server | ||
ARG SERVER | ||
WORKDIR /app | ||
COPY --from=server-build /app/${SERVER}/dist ./ | ||
ENTRYPOINT ["/sbin/tini", "--"] | ||
|
||
######################################### | ||
# App | ||
######################################### | ||
FROM server | ||
|
||
COPY --from=client-build /public ./public | ||
|
||
CMD ["node", "index.js"] | ||
|
108 changes: 108 additions & 0 deletions
108
apps/omsorgspengerutbetaling-arbeidstaker-soknad/dev-server.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const { createProxyMiddleware, fixRequestBody } = require('http-proxy-middleware'); | ||
const getAppSettings = require('./mock/AppSettings.cjs'); | ||
const { injectDecoratorServerSide } = require('@navikt/nav-dekoratoren-moduler/ssr/index.js'); | ||
const express = require('express'); | ||
const server = express(); | ||
server.use(express.json()); | ||
const path = require('path'); | ||
const mustacheExpress = require('mustache-express'); | ||
const compression = require('compression'); | ||
|
||
server.disable('x-powered-by'); | ||
|
||
server.use(compression()); | ||
|
||
require('dotenv').config(); | ||
server.set('views', `${__dirname}`); | ||
server.set('view engine', 'mustache'); | ||
server.engine('html', mustacheExpress()); | ||
|
||
server.use((req, res, next) => { | ||
res.removeHeader('X-Powered-By'); | ||
res.set('X-Frame-Options', 'SAMEORIGIN'); | ||
res.set('X-XSS-Protection', '1; mode=block'); | ||
res.set('X-Content-Type-Options', 'nosniff'); | ||
res.set('Referrer-Policy', 'no-referrer'); | ||
res.set('Feature-Policy', "geolocation 'none'; microphone 'none'; camera 'none'"); | ||
next(); | ||
}); | ||
|
||
async function injectDecorator(filePath) { | ||
return injectDecoratorServerSide({ | ||
env: 'dev', | ||
filePath, | ||
params: { | ||
enforceLogin: false, | ||
simple: true, | ||
}, | ||
}); | ||
} | ||
|
||
const startServer = async () => { | ||
server.get('/health/isAlive', (req, res) => res.sendStatus(200)); | ||
server.get('/health/isReady', (req, res) => res.sendStatus(200)); | ||
|
||
const indexHtmlPath = path.resolve(__dirname, 'index.html'); | ||
|
||
const htmlWithDecoratorInjected = await injectDecorator(indexHtmlPath); | ||
|
||
const renderedHtml = htmlWithDecoratorInjected.replaceAll( | ||
'{{{APP_SETTINGS}}}', | ||
JSON.stringify({ | ||
APP_VERSION: `${process.env.APP_VERSION}`, | ||
PUBLIC_PATH: `${process.env.PUBLIC_PATH}`, | ||
...getAppSettings(), | ||
}), | ||
); | ||
|
||
server.use( | ||
`${process.env.PUBLIC_PATH}/api`, | ||
// limiter, | ||
createProxyMiddleware({ | ||
target: 'http://localhost:8089/', | ||
changeOrigin: true, | ||
logger: console, | ||
on: { | ||
proxyReq: fixRequestBody, | ||
}, | ||
}), | ||
); | ||
|
||
const fs = require('fs'); | ||
fs.writeFileSync(path.resolve(__dirname, 'index-decorated.html'), renderedHtml); | ||
|
||
const vite = await require('vite').createServer({ | ||
root: __dirname, | ||
server: { | ||
middlewareMode: true, | ||
port: 8080, | ||
open: './index-decorated.html', | ||
}, | ||
}); | ||
|
||
server.get(/^\/(?!.*dist).*$/, (req, res, next) => { | ||
const ROOT_DIR = path.resolve(__dirname); | ||
const fullPath = path.resolve(ROOT_DIR, decodeURIComponent(req.path.substring(1))); | ||
|
||
if (!fullPath.startsWith(ROOT_DIR)) { | ||
res.status(403).send('Forbidden'); | ||
return; | ||
} | ||
|
||
const fileExists = fs.existsSync(fullPath); | ||
|
||
if ((!fileExists && !req.url.startsWith('/@')) || req.url === '/') { | ||
req.url = '/index-decorated.html'; | ||
} | ||
next(); | ||
}); | ||
|
||
server.use(vite.middlewares); | ||
|
||
const port = process.env.PORT || 8080; | ||
server.listen(port, () => { | ||
console.log(`App listening on port: ${port}`); | ||
}); | ||
}; | ||
|
||
startServer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
apps/omsorgspengerutbetaling-arbeidstaker-soknad/mock/AppSettings.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require('dotenv').config(); | ||
|
||
const process = require('process'); | ||
|
||
const getAppSettings = () => ({ | ||
APP_VERSION: `${process.env.APP_VERSION}`, | ||
GITHUB_REF_NAME: `${process.env.GITHUB_REF_NAME}`, | ||
IMAGE: `${process.env.IMAGE}`, | ||
PUBLIC_PATH: `${process.env.PUBLIC_PATH}`, | ||
|
||
K9_BRUKERDIALOG_PROSESSERING_API_URL: `${process.env.K9_BRUKERDIALOG_PROSESSERING_API_URL}`, | ||
K9_BRUKERDIALOG_PROSESSERING_FRONTEND_PATH: `${process.env.K9_BRUKERDIALOG_PROSESSERING_FRONTEND_PATH}`, | ||
|
||
SIF_PUBLIC_APPSTATUS_DATASET: `${process.env.SIF_PUBLIC_APPSTATUS_DATASET}`, | ||
SIF_PUBLIC_APPSTATUS_PROJECT_ID: `${process.env.SIF_PUBLIC_APPSTATUS_PROJECT_ID}`, | ||
SIF_PUBLIC_LOGIN_URL: `${process.env.SIF_PUBLIC_LOGIN_URL}`, | ||
SIF_PUBLIC_MINSIDE_URL: `${process.env.SIF_PUBLIC_MINSIDE_URL}`, | ||
SIF_PUBLIC_SKIP_ORGNUM_VALIDATION: `${process.env.SIF_PUBLIC_SKIP_ORGNUM_VALIDATION}`, | ||
}); | ||
|
||
module.exports = getAppSettings; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.