-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a91875e
commit b3db2f8
Showing
5 changed files
with
147 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const urlJoin = require('url-join'); | ||
|
||
const PROTOCOL = process.env.HOSTNAME_PROTOCOL || 'https'; | ||
const PORT = process.env.HOSTNAME_PORT || ''; | ||
|
||
module.exports = (hostname, path) => urlJoin( | ||
[ | ||
PROTOCOL, | ||
'://', | ||
hostname, | ||
PORT || '', | ||
].join(''), | ||
path, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const morgan = require('morgan'); | ||
const rfs = require('rotating-file-stream'); | ||
const composeFullTargetUrl = require('../compose-full-target-url'); | ||
|
||
/** | ||
* | ||
* @param {import('express').Application} app | ||
* @param {string} logDir | ||
*/ | ||
module.exports = (app, logDir) => { | ||
const stream = rfs.createStream('access.log', { | ||
// size: '10M', // rotate every 10 MegaBytes written | ||
interval: '1d', // rotate daily | ||
// compress: 'gzip' // compress rotated files | ||
maxFiles: Number(process.env.WEB_KEEP_ACESSS_FILES) || 45, | ||
path: logDir, | ||
}); | ||
|
||
morgan.token('xid', (req, res) => res.locals.xid || '-'); | ||
morgan.token('email', (req) => req.session?.email || '-'); | ||
// morgan.token('hostname', (req) => req.hostname || '-'); | ||
morgan.token( | ||
'url', | ||
/** | ||
* | ||
* @param {import('express').Request} req | ||
* @returns | ||
*/ | ||
(req) => composeFullTargetUrl(req.hostname, req.originalUrl), | ||
); | ||
|
||
app.use(morgan( | ||
':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" :email :xid', | ||
{ | ||
stream, | ||
}, | ||
)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters