Skip to content

Commit

Permalink
feat: adds request location and endless cookie expiring
Browse files Browse the repository at this point in the history
  • Loading branch information
migtarx committed Dec 18, 2023
1 parent 8cb34d8 commit b0b8737
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ morgan.token('user-ip', function(req) {
morgan.token('accepted-cookies', function(req) {
return Boolean(req.cookies['cookie-accepted']);
});
morgan.token('location', async function(req) {
const ip = execMode == "pro" ? req.headers['x-real-ip'] : req.ip;
const response = await fetch(`https://api.iplocation.net/?ip=${ip}`);
const data = await response.json();
const countryName = data.country_name;
return countryName;
});
morgan.token('id', function getId(req) {
return req.id;
});
app.use(assignId);
app.use(
morgan('New request from [:user-ip] \n{ \n Request ID: :id \n Method: :method \n Route: :url \n Status code: :status \n Response time: :response-time \n Accepted Cookies: :accepted-cookies \n}', {
morgan('{ \n Request ID: :id \n Request IP: :user-ip \n Request location: :location \n Method: :method \n Route: :url \n Status code: :status \n Response time: :response-time \n Accepted Cookies: :accepted-cookies \n}', {
skip: function (req, res) {
return skipStatics(req, res) || skipStatusServer(req, res);
}
Expand Down
2 changes: 1 addition & 1 deletion themes/hello-friend/assets/js/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ document.addEventListener("DOMContentLoaded", function() {
acceptButton.addEventListener('click', function() {
banner.classList.remove('slide-in-animation');
banner.classList.add('hide-out');
document.cookie = `cookie-accepted=true`
document.cookie = `cookie-accepted=true; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
});
});

0 comments on commit b0b8737

Please sign in to comment.