Skip to content

Commit

Permalink
added function to check if application is running locally
Browse files Browse the repository at this point in the history
  • Loading branch information
darcy521 committed May 4, 2024
1 parent 24d4972 commit f3b35b2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function session(options) {
}

// only send secure cookies via https
if (req.session.cookie.secure && !issecure(req, trustProxy)) {
if (req.session.cookie.secure && !issecure(req, trustProxy) && !isRunningLocally()) {
debug('not secured');
return;
}
Expand Down Expand Up @@ -654,6 +654,23 @@ function issecure(req, trustProxy) {
return proto === 'https';
}

/**
* Determine if application is running locally.
*
* @return {Boolean}
* @private
*/

function isRunningLocally() {
if (os.hostname() === 'localhost') {
return true;
}
var interfaces = os.networkInterfaces();
return Object.values(interfaces).flat().some(iface =>
iface.address === '127.0.0.1' || iface.address === '::1'
);
}

/**
* Set cookie on response.
*
Expand Down

0 comments on commit f3b35b2

Please sign in to comment.