Skip to content

Commit

Permalink
improve mortang token log
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ke committed Nov 16, 2023
1 parent 51344f5 commit c0ff553
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions swarmgate/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ export const app = express();
app.disable('etag');

morgan.token('client-cn', (req: any) => {
if (req.client.authorized && req.socket.getPeerCertificate().subject) {
return req.socket.getPeerCertificate().subject.CN;
if(!req.client || !req.client.authorized) {
return 'Unauthorized';
}
const cert = req.socket.getPeerCertificate();
if(!cert) {
return 'Unauthorized';
}
if (cert.subject) {
return cert.subject.CN;
}
return 'Unauthorized';
});
Expand Down

0 comments on commit c0ff553

Please sign in to comment.