Skip to content

Commit

Permalink
Merge branch '0-PROD' into 0-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-telescoop committed Dec 19, 2024
2 parents 5bd4238 + 3b32b18 commit 9c8eee6
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.59.2](https://github.com/betagouv/api-subventions-asso/compare/v0.59.1...v0.59.2) (2024-12-17)

### Bug Fixes

- **api:** rebuild req to log with string userId ([b09c7c6](https://github.com/betagouv/api-subventions-asso/commit/b09c7c6ab32652f8d7391f58f138418c2958bba5))

## [0.59.1](https://github.com/betagouv/api-subventions-asso/compare/v0.59.0...v0.59.1) (2024-12-16)

### Bug Fixes

- **api:** put userId elsewhere to not override req ([99c8dbf](https://github.com/betagouv/api-subventions-asso/commit/99c8dbffa56f6ff07f0f3a99772ea59497c02733))

# [0.59.0](https://github.com/betagouv/api-subventions-asso/compare/v0.58.2...v0.59.0) (2024-12-09)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packages": ["packages/*"],
"version": "0.59.0",
"version": "0.59.2",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions packages/api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.59.2](https://github.com/betagouv/api-subventions-asso/compare/v0.59.1...v0.59.2) (2024-12-17)

### Bug Fixes

- **api:** rebuild req to log with string userId ([b09c7c6](https://github.com/betagouv/api-subventions-asso/commit/b09c7c6ab32652f8d7391f58f138418c2958bba5))

## [0.59.1](https://github.com/betagouv/api-subventions-asso/compare/v0.59.0...v0.59.1) (2024-12-16)

### Bug Fixes

- **api:** put userId elsewhere to not override req ([99c8dbf](https://github.com/betagouv/api-subventions-asso/commit/99c8dbffa56f6ff07f0f3a99772ea59497c02733))

# [0.59.0](https://github.com/betagouv/api-subventions-asso/compare/v0.58.2...v0.59.0) (2024-12-09)

### Features
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api",
"version": "0.59.0",
"version": "0.59.2",
"description": "",
"main": "index.js",
"engines": {
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/dataProviders/db/stats/stats.port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export class StatsPort extends MongoPort<any> {
collectionName = "log";

async createIndexes() {
// await this.collection.createIndex({ timestamp: -1 });
await this.collection.createIndex({ "meta.req.user.email": 1 });
await this.collection.createIndex({ timestamp: -1 });
await this.collection.createIndex({ "meta.req.user._id": 1 });
// to handle in #1874
// await this.collection.createIndex({ "meta.req.url": 1 });
Expand Down
34 changes: 19 additions & 15 deletions packages/api/src/middlewares/LogMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import winston from "winston";
import expressWinston from "express-winston";
import "winston-mongodb";
import { ObjectId } from "mongodb";
import { UserDto } from "dto";
import { client } from "../shared/MongoConnection";

Expand All @@ -21,6 +22,18 @@ function recursiveFilter(obj: object) {
});
}

const requestWhitelist = [
"url",
"method",
"httpVersion",
"originalUrl",
"query",
"body",
"user",
"connection",
"headers",
];

export const expressLogger = () =>
expressWinston.logger({
transports: [
Expand All @@ -36,23 +49,14 @@ export const expressLogger = () =>
],
meta: true,
dynamicMeta: function (req, res) {
// completes generated meta in log
return {
req: { user: { _id: (req.user as UserDto)?._id?.toString() } },
};
if ((req.user as UserDto)?._id == null) return {};
// completes generated meta in log, careful it overrides nested values
const whiteReq = {};
requestWhitelist.map(propertyName => (whiteReq[propertyName] = req[propertyName]));
return { req: { ...whiteReq, user: { ...req.user, _id: (req.user as UserDto)?._id?.toString() } } };
},
msg: "Request: HTTP {{req.method}} {{req.url}}; ipAddress {{req.connection.remoteAddress}}",
requestWhitelist: [
"url",
"method",
"httpVersion",
"originalUrl",
"query",
"body",
"user",
"connection",
"headers",
],
requestWhitelist,
responseWhitelist: ["statusCode"],
ignoreRoute: req => {
return LOGGER_IGNORED_ROUTES.some(regex => regex.test(req.url));
Expand Down

0 comments on commit 9c8eee6

Please sign in to comment.