Skip to content

Commit

Permalink
feat(microservice): add custom user-agent header (#45)
Browse files Browse the repository at this point in the history
should allow to e.g. block requests coming from the proxy by identifying them via the user-agent
  • Loading branch information
reey committed Mar 21, 2024
1 parent 9357174 commit 52278e6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ FROM node:18-alpine As production
COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
COPY --chown=node:node --from=build /usr/src/app/dist ./dist

CMD [ "node", "dist/index.js" ]
CMD [ "node", "dist/src/index.js" ]

EXPOSE 80
5 changes: 5 additions & 0 deletions backend/src/header-adjustment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConnectionDetails } from "./connection-details";
import { IncomingHttpHeaders } from "http";
import { name, version } from "../package.json";

export class HeaderAdjustment {
private static headersToRemove = ["authorization"];
Expand All @@ -12,6 +13,10 @@ export class HeaderAdjustment {
continue;
}

if (key.toLowerCase() === "user-agent") {
keysToAdd[key] = `${name}/${version}`;
}

if (!key.startsWith(this.headerPrefix)) {
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"isolatedModules": false,
"esModuleInterop": true,
"skipLibCheck": true,
"strict": false
"strict": false,
"resolveJsonModule": true
},
"include": ["**/*.d.ts", "**/*.ts"],
"exclude": ["node_modules"]
Expand Down

0 comments on commit 52278e6

Please sign in to comment.