Configure timezone with TZ env var. Resolves #109

This commit is contained in:
ngosang 2021-05-30 11:28:43 +02:00
parent 10f8b83e83
commit 05f8ef95d9
3 changed files with 23 additions and 2 deletions

View File

@ -226,7 +226,8 @@ Name | Default | Notes
|--|--|--| |--|--|--|
LOG_LEVEL | info | Verbosity of the logging. Use `LOG_LEVEL=debug` for more information. LOG_LEVEL | info | Verbosity of the logging. Use `LOG_LEVEL=debug` for more information.
LOG_HTML | false | Only for debugging. If `true` all HTML that passes through the proxy will be logged to the console in `debug` level. LOG_HTML | false | Only for debugging. If `true` all HTML that passes through the proxy will be logged to the console in `debug` level.
CAPTCHA_SOLVER | none | Captcha solving method. It used when a captcha is encountered. See the Captcha Solvers section. CAPTCHA_SOLVER | none | Captcha solving method. It is used when a captcha is encountered. See the Captcha Solvers section.
TZ | UTC | Timezone used in the logs and the web browser. Example: `TZ=Europe/London`.
HEADLESS | true | Only for debugging. To run the web browser in headless mode or visible. HEADLESS | true | Only for debugging. To run the web browser in headless mode or visible.
PORT | 8191 | Listening port. You don't need to change this if you are running on Docker. PORT | 8191 | Listening port. You don't need to change this if you are running on Docker.
HOST | 0.0.0.0 | Listening interface. You don't need to change this if you are running on Docker. HOST | 0.0.0.0 | Listening interface. You don't need to change this if you are running on Docker.

View File

@ -9,6 +9,7 @@ services:
- LOG_LEVEL=${LOG_LEVEL:-info} - LOG_LEVEL=${LOG_LEVEL:-info}
- LOG_HTML=${LOG_HTML:-false} - LOG_HTML=${LOG_HTML:-false}
- CAPTCHA_SOLVER=${CAPTCHA_SOLVER:-none} - CAPTCHA_SOLVER=${CAPTCHA_SOLVER:-none}
- TZ=Europe/London
ports: ports:
- "${PORT:-8191}:8191" - "${PORT:-8191}:8191"
restart: unless-stopped restart: unless-stopped

View File

@ -2,6 +2,25 @@ let requests = 0
const LOG_HTML: boolean = process.env.LOG_HTML == 'true'; const LOG_HTML: boolean = process.env.LOG_HTML == 'true';
function toIsoString(date: Date) {
// this function fixes Date.toISOString() adding timezone
let tzo = -date.getTimezoneOffset(),
dif = tzo >= 0 ? '+' : '-',
pad = function(num: number) {
let norm = Math.floor(Math.abs(num));
return (norm < 10 ? '0' : '') + norm;
};
return date.getFullYear() +
'-' + pad(date.getMonth() + 1) +
'-' + pad(date.getDate()) +
'T' + pad(date.getHours()) +
':' + pad(date.getMinutes()) +
':' + pad(date.getSeconds()) +
dif + pad(tzo / 60) +
':' + pad(tzo % 60);
}
export default { export default {
incRequests: () => { requests++ }, incRequests: () => { requests++ },
html(html: string) { html(html: string) {
@ -12,7 +31,7 @@ export default {
{level: process.env.LOG_LEVEL || 'info', {level: process.env.LOG_LEVEL || 'info',
prefix(level: string) { prefix(level: string) {
const req = (requests > 0) ? ` REQ-${requests}` : ''; const req = (requests > 0) ? ` REQ-${requests}` : '';
return `${new Date().toISOString()} ${level.toUpperCase()}${req}` return `${toIsoString(new Date())} ${level.toUpperCase()}${req}`
} }
} }
) )