Merge pull request #241 from JazzFisch/add-logger

Add Winston for log handling
This commit is contained in:
Ben Phelps 2022-09-21 09:03:52 +03:00 committed by GitHub
commit c024c4f01c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 248 additions and 14 deletions

View file

@ -1,3 +1,4 @@
import logger from "utils/logger";
import genericProxyHandler from "utils/proxies/generic";
import credentialedProxyHandler from "utils/proxies/credentialed";
import rutorrentProxyHandler from "utils/proxies/rutorrent";
@ -99,20 +100,27 @@ const serviceProxyHandlers = {
};
export default async function handler(req, res) {
const { type } = req.query;
try {
const { type } = req.query;
const serviceProxyHandler = serviceProxyHandlers[type];
const serviceProxyHandler = serviceProxyHandlers[type];
if (serviceProxyHandler) {
if (serviceProxyHandler instanceof Function) {
return serviceProxyHandler(req, res);
if (serviceProxyHandler) {
if (serviceProxyHandler instanceof Function) {
return serviceProxyHandler(req, res);
}
const { proxy, maps } = serviceProxyHandler;
if (proxy) {
return proxy(req, res, maps);
}
}
const { proxy, maps } = serviceProxyHandler;
if (proxy) {
return proxy(req, res, maps);
}
logger.debug("Unknown proxy service type: %s", type);
return res.status(403).json({ error: "Unkown proxy service type" });
}
catch (ex) {
logger.error(ex);
return res.status(500).send({ error: "Unexpected error" });
}
return res.status(403).json({ error: "Unkown proxy service type" });
}