Skip to content

Commit

Permalink
Add Winston for log handling
Browse files Browse the repository at this point in the history
- write log data to 'homepage.log'
  • Loading branch information
JazzFisch committed Sep 21, 2022
1 parent 539e0f0 commit 280bb5f
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
.DS_Store
*.pem

# log files
error.log
homepage.log

# debug
npm-debug.log*
yarn-debug.log*
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"rutorrent-promise": "^2.0.0",
"shvl": "^3.0.0",
"swr": "^1.3.0",
"tough-cookie": "^4.1.2"
"tough-cookie": "^4.1.2",
"winston": "^3.8.2"
},
"devDependencies": {
"autoprefixer": "^10.4.9",
Expand Down
141 changes: 140 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 19 additions & 11 deletions src/pages/api/services/proxy.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -98,20 +99,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" });
}
Loading

0 comments on commit 280bb5f

Please sign in to comment.