Skip to content

Commit

Permalink
fix: skips static files and renames user ip header
Browse files Browse the repository at this point in the history
  • Loading branch information
migtarx committed Dec 9, 2023
1 parent daf64c1 commit b0668ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ app.use(helmet({
contentSecurityPolicy: false
}));
morgan.token('user-ip', function(req) {
return execMode == "pro" ? req.headers['X-Real-IP'] : req.ip;
return execMode == "pro" ? req.headers['x-real-ip'] : req.ip;
});
morgan.token('accepted-cookies', function(req) {
return Boolean(req.cookies['cookie-accepted']);
Expand Down
7 changes: 6 additions & 1 deletion src/middlewares/morgan.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ function assignId(req, res, next) {

function skipStatics(req, res) {
const staticFilesPrefixes = ['/css', '/js', '/images', '/img', '/fonts'];
return staticFilesPrefixes.some(prefix => req.originalUrl.startsWith(prefix));
const fileExtensionsToSkip = ['.js', '.css', '.png', '.jpg', '.jpeg'];

const shouldSkipFileExtension = fileExtensionsToSkip.some(extension => req.originalUrl.endsWith(extension));
const shouldSkipStaticFile = staticFilesPrefixes.some(prefix => req.originalUrl.startsWith(prefix));

return shouldSkipFileExtension || shouldSkipStaticFile;
}

function skipStatusServer(req, res) {
Expand Down

0 comments on commit b0668ff

Please sign in to comment.