diff --git a/package-lock.json b/package-lock.json index 6116f77..3e149fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@mui/material": "^5.15.15", "@statisticsnorway/ssb-component-library": "^2.0.99", + "body-parser": "^1.20.2", "dotenv": "^16.4.5", "effect": "^3.3.1", "eslint-config-prettier": "^9.1.0", diff --git a/package.json b/package.json index aba6ae7..9450b7c 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@mui/material": "^5.15.15", "@statisticsnorway/ssb-component-library": "^2.0.99", + "body-parser": "^1.20.2", "dotenv": "^16.4.5", "effect": "^3.3.1", "eslint-config-prettier": "^9.1.0", diff --git a/server.js b/server.js index fff0ab0..9e0be40 100644 --- a/server.js +++ b/server.js @@ -5,6 +5,7 @@ import { getReasonPhrase } from 'http-status-codes' import proxy from 'express-http-proxy' import dotenv from 'dotenv' import cache from 'memory-cache' +import bodyParser from 'body-parser' if (!process.env.DAPLA_TEAM_API_URL) { dotenv.config({ path: './.env.local' }) @@ -33,6 +34,11 @@ app.use( }) ) +app.post('/log', bodyParser.text({ type: '*/*' }), (req, res) => { + console.log(req.body) + res.send('Ok') +}) + app.use( '/api', proxy(DAPLA_TEAM_API_URL, { diff --git a/src/pages/TeamOverview/TeamOverview.tsx b/src/pages/TeamOverview/TeamOverview.tsx index f2b7dc5..38c58c6 100644 --- a/src/pages/TeamOverview/TeamOverview.tsx +++ b/src/pages/TeamOverview/TeamOverview.tsx @@ -15,6 +15,7 @@ import FormattedTableColumn from '../../components/FormattedTableColumn/Formatte import { User } from '../../services/userProfile' import { isAuthorizedToCreateTeam } from '../../services/createTeam' import { Effect } from 'effect' +import { customLogger } from '../../utils/logger.ts' const MY_TEAMS_TAB = { title: 'Mine team', @@ -79,7 +80,15 @@ const TeamOverview = () => { if (!user) return Effect.promise(() => isDaplaAdmin(user.principal_name)) - .pipe(Effect.runPromise) + .pipe( + Effect.tap((isDaplaAdmin: boolean) => + Effect.logInfo( + `username: ${user.principal_name}; job-title: ${user.job_title}; is-dapla-admin: ${isDaplaAdmin}` + ) + ), + Effect.provide(customLogger), + Effect.runPromise + ) .then((isDaplaAdmin: boolean) => setIsAuthorized(isAuthorizedToCreateTeam(isDaplaAdmin, user.job_title))) }, []) diff --git a/src/utils/logger.ts b/src/utils/logger.ts new file mode 100644 index 0000000..411a833 --- /dev/null +++ b/src/utils/logger.ts @@ -0,0 +1,12 @@ +import { Console, Effect, Logger } from 'effect' +import * as Http from '@effect/platform/HttpClient' + +const logger = Logger.make(({ logLevel, message }) => { + const logMsg = `[${logLevel.label}] ${message}` + Console.log(logMsg).pipe( + Effect.zipRight(Http.request.post('/log').pipe(Http.request.textBody(logMsg), Http.client.fetchOk, Effect.scoped)), + Effect.runPromise + ) +}) + +export const customLogger = Logger.replace(Logger.defaultLogger, logger)