mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2026-04-21 23:42:40 +02:00
Validate environment variables at startup. resolves #101
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user