mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2025-06-08 04:25:25 +00:00
Validate environment variables at startup. resolves #101
This commit is contained in:
parent
c48d342b9c
commit
8aa7723f45
12
README.md
12
README.md
@ -224,12 +224,12 @@ moment there is nothing setup to do so. If this is something you need feel free
|
||||
|
||||
Name | Default | Notes
|
||||
|--|--|--|
|
||||
LOG_LEVEL | info | Used to change the verbosity of the logging. Use `LOG_LEVEL=debug` for more information.
|
||||
LOG_HTML | false | Used for debugging. If `true` all HTML that passes through the proxy will be logged to the console in `debug` level.
|
||||
PORT | 8191 | Change this if you already have a process running on port `8191`.
|
||||
HOST | 0.0.0.0 | This shouldn't need to be messed with but if you insist, it's here!
|
||||
CAPTCHA_SOLVER | none | This is used to select which captcha solving method it used when a captcha is encountered.
|
||||
HEADLESS | true | This is used to debug the browser by not running it in headless mode.
|
||||
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.
|
||||
CAPTCHA_SOLVER | none | Captcha solving method. It used when a captcha is encountered. See the Captcha Solvers section.
|
||||
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.
|
||||
HOST | 0.0.0.0 | Listening interface. You don't need to change this if you are running on Docker.
|
||||
|
||||
Environment variables are set differently depending on the operating system. Some examples:
|
||||
* Docker: Take a look at the Docker section in this document. Environment variables can be set in the `docker-compose.yml` file or in the Docker CLI command.
|
||||
|
@ -30,12 +30,12 @@ export default (): Solver => {
|
||||
throw Error(`The solver '${method}' is not a valid captcha solving method.`)
|
||||
} else {
|
||||
console.error(e)
|
||||
throw Error(`An error occured loading the solver '${method}'.`)
|
||||
throw Error(`An error occurred loading the solver '${method}'.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.info(`Using '${method} to solve the captcha.`);
|
||||
log.info(`Using '${method}' to solve the captcha.`);
|
||||
|
||||
return captchaSolvers[method]
|
||||
}
|
||||
|
25
src/index.ts
25
src/index.ts
@ -2,11 +2,33 @@ import log from './log'
|
||||
import { createServer, IncomingMessage, ServerResponse } from 'http';
|
||||
import { RequestContext } from './types'
|
||||
import Router, { BaseAPICall } from './routes'
|
||||
import getCaptchaSolver from "./captcha";
|
||||
|
||||
const version: string = "v" + require('../package.json').version
|
||||
const serverPort: number = Number(process.env.PORT) || 8191
|
||||
const serverHost: string = process.env.HOST || '0.0.0.0'
|
||||
|
||||
function validateEnvironmentVariables() {
|
||||
// ip and port variables are validated by nodejs
|
||||
if (process.env.LOG_LEVEL && ['error', 'warn', 'info', 'verbose', 'debug'].indexOf(process.env.LOG_LEVEL) == -1) {
|
||||
log.error(`The environment variable 'LOG_LEVEL' is wrong. Check the documentation.`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.env.LOG_HTML && ['true', 'false'].indexOf(process.env.LOG_HTML) == -1) {
|
||||
log.error(`The environment variable 'LOG_HTML' is wrong. Check the documentation.`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.env.HEADLESS && ['true', 'false'].indexOf(process.env.HEADLESS) == -1) {
|
||||
log.error(`The environment variable 'HEADLESS' is wrong. Check the documentation.`);
|
||||
process.exit(1);
|
||||
}
|
||||
try {
|
||||
getCaptchaSolver();
|
||||
} catch (e) {
|
||||
log.error(`The environment variable 'CAPTCHA_SOLVER' is wrong. ${e.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function errorResponse(errorMsg: string, res: ServerResponse, startTimestamp: number) {
|
||||
log.error(errorMsg)
|
||||
@ -64,6 +86,9 @@ function validateIncomingRequest(ctx: RequestContext, params: BaseAPICall) {
|
||||
return true
|
||||
}
|
||||
|
||||
// init
|
||||
validateEnvironmentVariables();
|
||||
|
||||
createServer((req: IncomingMessage, res: ServerResponse) => {
|
||||
const startTimestamp = Date.now()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user